Êîðïîðàöèÿ Sun Microsystems © 2000 ã. Âñå ïðàâà çàùèùåíû. 901 San Antonio Road, Palo Alto, øò. Êàëèôîðíèÿ, 94303, ÑØÀ. ÇÀßÂËÅÍÈÅ ÎÁ ÎÃÐÀÍÈ×ÅÍÈÈ ÏÐÀÂ: Èñïîëüçîâàíèå, êîïèðîâàíèå è ïóá- ëèêàöèÿ ýòîé êíèãè ïîïàäàþò ïîä îãðàíè÷åíèÿ ïðàâèòåëüñòâà ÑØÀ DFARS 252.227-7013 (c)(1)(ii) è FAR 52.227-19. Ðåàëèçàöèè ïëàòôîðìû, îïèñûâàåìûå â ýòîé êíèãå, ìîãóò áûòü çàùèùåíû îäíèì èëè íåñêîëüêèìè ïàòåíòàìè ÑØÀ, ïàòåíòàìè äðóãèõ ñòðàí èëè ïàòåíòíûìè çàÿâêàìè, íàõîäÿùèìèñÿ íà ðàññìîòðåíèè. Sun, Sun Microsystems, ëîãîòèï Sun, Java, Java Software, Java Card, Java SDK, Java 2 Standard Edtition è Java 2 Enterprise Edition ÿâëÿþòñÿ òîâàðíûìè çíàêàìè èëè çàðåãèñòðèðîâàííûìè òîâàðíûìè çíàêàìè êîðïîðàöèè Sun Microsystems. UNIX® ÿâëÿåòñÿ çàðåãèñòðèðîâàííûì òîâàðíûì çíàêîì â ÑØÀ è äðóãèõ ñòðàíàõ, ýêñêëþçèâíàÿ ëèöåíçèÿ íà èñïîëüçîâàíèå êîòîðîãî ïðèíàäëåæèò êîìïàíèè X/Open. Äðóãèå íàèìåíîâàíèÿ è òîâàðíûå çíàêè ÿâëÿþòñÿ ñîáñò- âåííîñòüþ ñâîèõ çàêîííûõ âëàäåëüöåâ. ÌÀÒÅÐÈÀËÛ ÏÐÅÄÎÑÒÀÂËßÞÒÑß ÏÎ ÏÐÈÍÖÈÏÓ "ÊÀÊ ÅÑÒÜ", ÁÅÇ ÊÀÊÈÕ-ËÈÁÎ ßÂÍÛÕ ÈËÈ ÏÎÄÐÀÇÓÌÅÂÀÅÌÛÕ ÃÀÐÀÍÒÈÉ, ÂÊËÞ- ×Àß,  ×ÈÑËÅ ÏÐÎ×ÅÃÎ, ÃÀÐÀÍÒÈÈ Â ÎÒÍÎØÅÍÈÈ ÈÕ ÐÛÍÎ×ÍÛÕ ÊÀ×ÅÑÒÂ, ÍÅÍÀÐÓØÅÍÈß ÏÐÀ ÍÀ ÈÍÒÅËËÅÊÒÓÀËÜÍÓÞ ÑÎÁÑÒ- ÂÅÍÍÎÑÒÜ ÈËÈ ÏÐÈÃÎÄÍÎÑÒÈ Ê ÈÑÏÎËÜÇÎÂÀÍÈÞ Â ÒÅÕ ÈËÈ ÈÍÛÕ ÊÎÍÊÐÅÒÍÛÕ ÖÅËßÕ. ÝÒÀ ÏÓÁËÈÊÀÖÈß ÌÎÆÅÒ ÑÎÄÅÐÆÀÒÜ ÒÅÕÍÈ×ÅÑÊÈÅ ÍÅÒÎ×ÍÎÑÒÈ ÈËÈ ÎÏÅ×ÀÒÊÈ.  ÍÅÅ ÌÎÃÓÒ ÂÍÎÑÈÒÜÑß ÈÇÌÅÍÅÍÈß; ÝÒÈ ÈÇ- ÌÅÍÅÍÈß ÁÓÄÓÒ ÂÊËÞ×ÀÒÜÑß Â ÍÎÂÛÅ ÈÇÄÀÍÈß ÍÀÑÒÎßÙÅÉ ÏÓÁËÈÊÀÖÈÈ. ÊÎÐÏÎÐÀÖÈß SUN MICROSYSTEMS ÈÌÅÅÒ ÏÐÀÂÎ Â ËÞÁÎÅ ÂÐÅÌß ÂÍÎÑÈÒÜ ÓÑÎÂÅÐØÅÍÑÒÂÎÂÀÍÈß È/ÈËÈ ÈÇÌÅÍÅÍÈß Â ÏÐÎÄÓÊÒ (ÏÐÎÄÓÊÒÛ), ÎÏÈÑÀÍÈß ÊÎÒÎÐÛÕ ÏÐÈÂÎÄßÒÑß Â ÍÀÑÒÎßÙÅÉ ÏÓÁËÈÊÀÖÈÈ. Содержание Ïðåäèñëîâèå......................................................................................................................10 Îá ýòîé êíèãå ....................................................................................................................12 ×ÀÑÒÜ 1. ÂÂÅÄÅÍÈÅ.....................................................................................................15 Ãëàâà 1. Íà÷íåì ñíà÷àëà..................................................................................................16 1.1. Ñìàðò-êàðòû.........................................................................................................16 1.1.1. Êðàòêàÿ èñòîðèÿ..........................................................................................17 1.1.2. Ïðåèìóùåñòâà ñìàðò-êàðò..........................................................................17 1.1.3. Îáëàñòè ïðèìåíåíèÿ...................................................................................18 1.2. Ïðîáëåìû ðàçðàáîòêè ïðèëîæåíèé äëÿ ñìàðò-êàðò.........................................20 1.3. Èñïîëüçîâàíèå òåõíîëîãèè Java äëÿ ñìàðò-êàðò...............................................21 1.3.1. Ïðåèìóùåñòâà òåõíîëîãèè Java Card.........................................................21 1.3.2. Êðàòêàÿ èñòîðèÿ òåõíîëîãèè Java Card......................................................22 Ãëàâà 2. Ââåäåíèå â ìèð ñìàðò-êàðò ...............................................................................24 2.1. Îáçîð òåõíîëîãèè ñìàðò-êàðò.............................................................................24 2.2. Îñíîâíûå òèïû ñìàðò-êàðò ................................................................................25 2.2.1. Ñðàâíåíèå êàðò ïàìÿòè è êàðò ñî âñòðîåííûì ìèêðîïðîöåññîðîì............25 2.2.2. Ñðàâíåíèå êîíòàêòíûõ è áåñêîíòàêòíûõ êàðò .........................................26 2.3. Àïïàðàòíûå ñðåäñòâà ñìàðò-êàðò........................................................................27 2.3.1. Êîíòàêòû ñìàðò-êàðòû ...............................................................................27 2.3.2. Öåíòðàëüíûé ïðîöåññîð ñìàðò-êàðòû.......................................................28 2.3.3. Ñîïðîöåññîðû ñìàðò-êàðò..........................................................................28 2.3.4. Ñèñòåìà ïàìÿòè ñìàðò-êàðò........................................................................28 2.4. Âçàèìîäåéñòâèå ñî ñìàðò-êàðòàìè....................................................................30 2.4.1. Óñòðîéñòâà ñ÷èòûâàíèÿ êàðò è õîñò-ïðèëîæåíèÿ ....................................30 2.4.2. Ìîäåëü âçàèìîäåéñòâèÿ ñî ñìàðò-êàðòàìè...............................................30 2.4.3. Ïðîòîêîë APDU..........................................................................................31 2.4.4. Ïðîòîêîë TPDU..........................................................................................33 2.4.5. Ñîîáùåíèå ATR..........................................................................................33 2.5. Îïåðàöèîííûå ñèñòåìû ñìàðò-êàðò ..................................................................33 2.5.1. Ôàéëîâûå ñèñòåìû ñìàðò-êàðò ..................................................................34 2.5.2. Êîðíåâîé êàòàëîã (Master File) ..................................................................35 2.5.3. Êàòàëîã (Dedicated File)..............................................................................35 2.5.4. Ôàéë äàííûõ (Elementary File)...................................................................35 2.6. Ïðîãðàììíîå îáåñïå÷åíèå ñìàðò-êàðò..............................................................35 2.7. Ñòàíäàðòû è ñïåöèôèêàöèè ñìàðò-êàðò............................................................36 2.7.1. Ñòàíäàðòû ISO 7816.....................................................................................37 2.7.2. Ñòàíäàðòû GSM ..........................................................................................37 2.7.3. Ñïåöèôèêàöèÿ EMV...................................................................................37 2.7.4. Ñïåöèôèêàöèè Open Platform....................................................................38 2.7.5. Èíòåãðèðîâàííàÿ ñðåäà OpenCard Framework..........................................38 2.7.6. Ñïåöèôèêàöèè PC/SC................................................................................38 ×ÀÑÒÜ 2. ÒÅÕÍÎËÎÃÈß JAVA CARD..........................................................................39 Ãëàâà 3. Îáçîð òåõíîëîãèè Java Card..............................................................................40 3.1. Îáçîð àðõèòåêòóðû ..............................................................................................40 3.2. Ïîäìíîæåñòâî ÿçûêà Java Card ..........................................................................41 3.3. Âèðòóàëüíàÿ ìàøèíà Java Card...........................................................................42 6 Ñîäåðæàíèå 3.3.1. Ôàéëû CAP è ýêñïîðòíûå ôàéëû..............................................................42 3.3.2. Êîíâåðòåð Java Card....................................................................................43 3.3.3. Èíòåðïðåòàòîð Java Card.............................................................................44 3.4. Èíñòàëëÿòîð Java Card è âíåøíÿÿ èíñòàëëÿöèîííàÿ ïðîãðàììà....................45 3.5. Ñðåäà èñïîëíåíèÿ Java Card ...............................................................................46 3.5.1. Âðåìÿ ñóùåñòâîâàíèÿ JCRE.......................................................................47 3.5.2. Êàê ðàáîòàåò JCRE âî âðåìÿ ñåàíñà ñâÿçè ñ óñòðîéñòâîì ñ÷èòûâàíèÿ........48 3.5.3. Äîïîëíèòåëüíûå âîçìîæíîñòè ñðåäû èñïîëíåíèÿ Java Card..................49 3.6. API, ïîääåðæèâàåìûå ïëàòôîðìîé Java Card....................................................49 3.6.1. Ïàêåò java.lang........................................................................................50 3.6.2. Ïàêåò javacard.framework.....................................................................50 3.6.3. Ïàêåò javacard.security.......................................................................51 3.6.4. Ïàêåò javacardx.crypto.........................................................................51 3.7. Àïëåòû Java Card..................................................................................................52 3.8. Ñîãëàøåíèå î ïðèñâàèâàíèè èìåí ïàêåòàì è àïëåòàì.....................................52 3.9. Ïðîöåññ ðàçðàáîòêè àïëåòà.................................................................................53 3.10. Èíñòàëëÿöèÿ àïëåòà...........................................................................................55 3.10.1. Àïëåòû ROM..............................................................................................55 3.10.2. Ïðåäîïðåäåëåííûå è çàãðóæàåìûå àïëåòû .............................................55 3.10.3. Èíñòàëëÿöèÿ çàãðóæàåìûõ àïëåòîâ .........................................................56 3.10.4. Îáðàáîòêà îøèáîê â ïðîöåññå èíñòàëëÿöèè àïëåòà...............................57 3.10.5. Îãðàíè÷åíèÿ èíñòàëëÿöèè.......................................................................57 Ãëàâà 4. Îáúåêòû Java Card..............................................................................................58 4.1. Ìîäåëü ïàìÿòè Java Card.....................................................................................58 4.2. Ïîñòîÿííûå îáúåêòû...........................................................................................59 4.3. Âðåìåííûå îáúåêòû.............................................................................................60 4.3.1. Ñâîéñòâà âðåìåííûõ îáúåêòîâ...................................................................60 4.3.2. Òèïû âðåìåííûõ îáúåêòîâ .........................................................................61 4.3.3. Ñîçäàíèå âðåìåííûõ îáúåêòîâ...................................................................62 4.3.4. Çàïðîñû ê âðåìåííûì îáúåêòàì ................................................................62 4.4. Êðàòêî î ñîçäàíèè è óäàëåíèè îáúåêòîâ............................................................63 Ãëàâà 5. Àòîìàðíîñòü è òðàíçàêöèè................................................................................64 5.1. Àòîìàðíîñòü.........................................................................................................64 5.2. Àòîìàðíîå îáíîâëåíèå áëîêà äàííûõ â ìàññèâå...............................................65 5.3. Òðàíçàêöèè...........................................................................................................65 5.3.1. Ôèêñàöèÿ òðàíçàêöèè.................................................................................66 5.3.2. Ïðåðûâàíèå òðàíçàêöèè.............................................................................66 5.3.3. Âëîæåííûå òðàíçàêöèè ..............................................................................67 5.3.4. Ðàçìåð áóôåðà òðàíçàêöèé .........................................................................67 5.3.5. TransactionException............................................................................68 5.3.6. Èçìåíåíèå çíà÷åíèé ëîêàëüíûõ ïåðåìåííûõ è âðåìåííûõ îáúåêòîâ â ïðîöåññå âûïîëíåíèÿ òðàíçàêöèè..........................................................68 Ãëàâà 6. Èñêëþ÷åíèÿ Java Card è èõ îáðàáîòêà.............................................................71 6.1. Èñêëþ÷åíèÿ â ïàêåòå java.lang ......................................................................71 6.2. Èñêëþ÷åíèÿ Java Card.........................................................................................72 6.2.1. Êîä ïðè÷èíû èñêëþ÷åíèé Java Card.........................................................73 6.2.2. Âîçáóæäåíèå èñêëþ÷åíèé â Java Card.......................................................73 6.2.3. ISOException.............................................................................................74 6.2.4. UserException...........................................................................................75 Ñîäåðæàíèå 7 Ãëàâà 7. Àïëåòû Java Card................................................................................................76 7.1. Îáçîð àïëåòîâ.......................................................................................................76 7.1.1. Èíñòàëëÿöèÿ è âûïîëíåíèå àïëåòîâ.........................................................76 7.1.2. Âçàèìîäåéñòâèå õîñò-ñèñòåìû è àïëåòîâ..................................................77 7.2. Êëàññ javacard.framework.Applet...............................................................77 7.3. Ìåòîä install....................................................................................................78 7.3.1. Ñîçäàíèå îáúåêòîâ â êîíñòðóêòîðå àïëåòà................................................80 7.3.2. Ðåãèñòðàöèÿ ýêçåìïëÿðà àïëåòà â JCRE....................................................80 7.3.3. Îáðàáîòêà ïàðàìåòðîâ èíñòàëëÿöèè .........................................................81 7.3.4. Äîïîëíèòåëüíàÿ èíèöèàëèçàöèÿ àïëåòîâ.................................................83 7.4. Ìåòîä select ......................................................................................................83 7.4.1. Ôîðìàò è îáðàáîòêà êîìàíäû SELECT APDU.........................................84 7.4.2. Àïëåò ïî óìîë÷àíèþ...................................................................................85 7.5. Ìåòîä deselect..................................................................................................85 7.6. Ìåòîä process....................................................................................................86 7.7. Äðóãèå ìåòîäû êëàññà javacard.framework.Applet....................................86 Ãëàâà 8. Ðàáîòà ñ ïàêåòàìè äàííûõ APDU.....................................................................88 8.1. Êëàññ APDU ...........................................................................................................88 8.1.1. Îáúåêò APDU ..............................................................................................89 8.1.2. Ðàçìåð áóôåðà APDU..................................................................................89 8.2. Èíòåðôåéñ ISO7816............................................................................................89 8.3. Ðàáîòà ñ ïàêåòàìè APDU â àïëåòàõ....................................................................90 8.3.1. Ïîëó÷åíèå ññûëêè íà áóôåð APDU...........................................................90 8.3.2. Ïðîâåðêà çàãîëîâêà êîìàíäû APDU.........................................................90 8.3.3. Èçâëå÷åíèå äàííûõ èç êîìàíäû APDU ....................................................91 8.3.3.1. Ïîëó÷åíèå áîëüøèõ áëîêîâ äàííûõ.................................................92 8.3.4. Îáðàáîòêà êîìàíäû APDU è ãåíåðàöèÿ îòâåòíûõ äàííûõ......................94 8.3.5. Îòïðàâêà îòâåòíûõ äàííûõ APDU.............................................................94 8.3.5.1. Îòïðàâêà äàííûõ èç äðóãèõ ìåñòîïîëîæåíèé.................................96 8.3.5.2. Îòïðàâêà áîëüøèõ îòâåòíûõ áëîêîâ äàííûõ...................................97 8.3.6. Âîçâðàùåíèå ñëîâà ñîñòîÿíèÿ ...................................................................98 8.4. Ñïîñîáû îáðàáîòêè êîìàíä APDU, çàâèñÿùèå îò ïðîòîêîëà.........................99 8.4.1. Ìåòîä getProtocol.................................................................................100 8.4.2. Ìåòîä getInBlockSize...........................................................................100 8.4.3. Ìåòîä getOutBlockSize.........................................................................101 8.4.4. Ìåòîä setOutgoingNoChaining............................................................102 8.4.5. Ìåòîä getNAD............................................................................................102 8.4.6. Ìåòîä waitExtension.............................................................................102 8.5. Âûâîäû ...............................................................................................................103 Ãëàâà 9. Áðàíäìàóýð àïëåòîâ è ñîâìåñòíîå èñïîëüçîâàíèå îáúåêòîâ........................105 9.1. Áðàíäìàóýð àïëåòîâ...........................................................................................105 9.1.1. Êîíòåêñòû..................................................................................................106 9.1.2. Âëàäåíèå îáúåêòàìè..................................................................................107 9.1.3. Äîñòóï ê îáúåêòàì.....................................................................................107 9.1.4. Êîíòåêñòû è äîñòóï ê âðåìåííûì ìàññèâàì...........................................108 9.1.5. Ñòàòè÷åñêèå ïîëÿ è ìåòîäû......................................................................108 9.2. Èñïîëüçîâàíèå îáúåêòîâ ðàçíûìè êîíòåêñòàìè ............................................109 9.2.1. Ïåðåêëþ÷åíèå êîíòåêñòîâ .......................................................................109 9.2.2. Ïðèâèëåãèè JCRE.....................................................................................110 9.2.3. Îáúåêòû–òî÷êè âõîäà â JCRE..................................................................110 8 Ñîäåðæàíèå 9.2.4. Ãëîáàëüíûå ìàññèâû.................................................................................111 9.2.5. Èíòåðôåéñíûé ìåõàíèçì ñîâìåñòíîãî èñïîëüçîâàíèÿ îáúåêòîâ.........112 9.2.5.1. Èíòåðôåéñ ñîâìåñòíîãî èñïîëüçîâàíèÿ......................................112 9.2.5.2. Îáúåêò èíòåðôåéñà ñîâìåñòíîãî èñïîëüçîâàíèÿ........................112 9.2.5.3. Ïðèíöèïû äåéñòâèÿ èíòåðôåéñíîãî ìåõàíèçìà ñîâìåñòíîãî èñïîëüçîâàíèÿ îáúåêòîâ ...............................................................113 9.2.5.4. Ïðèìåð ñîâìåñòíîãî èñïîëüçîâàíèÿ îáúåêòà ðàçíûìè àïëåòàìè .........................................................................114 9.2.5.5. Ñîçäàíèå îáúåêòà èíòåðôåéñà ñîâìåñòíîãî èñïîëüçîâàíèÿ......115 9.2.5.6. Çàïðîñ îáúåêòà èíòåðôåéñà ñîâìåñòíîãî èñïîëüçîâàíèÿ..........116 9.2.5.7. Ïðèìåíåíèå îáúåêòà èíòåðôåéñà ñîâìåñòíîãî èñïîëüçîâàíèÿ ...............................................................................117 9.2.5.8. Ïåðåêëþ÷åíèÿ êîíòåêñòîâ â ïðîöåññå ñîâìåñòíîãî èñïîëüçîâàíèÿ îáúåêòîâ ...............................................................119 9.2.5.9. Òèïû ïàðàìåòðîâ è ðåçóëüòàòîâ ìåòîäîâ èíòåðôåéñà ñîâìåñòíîãî èñïîëüçîâàíèÿ..........................................................120 9.2.5.10.Àóòåíòèôèêàöèÿ êëèåíòñêîãî àïëåòà ..........................................121 9.2.5.11.Ìåòîä getPreviousContextAID................................................124 9.2.5.12.Âûâîäû...........................................................................................125 Ãëàâà 10. Ïðîãðàììèðîâàíèå êðèïòîãðàôè÷åñêèõ ôóíêöèé.....................................127 10.1. Ââåäåíèå â êðèïòîãðàôèþ...............................................................................127 10.1.1. Øèôðîâàíèå è ðàñøèôðîâêà.................................................................128 10.1.2. Äàéäæåñò ñîîáùåíèÿ...............................................................................130 10.1.3. Öèôðîâàÿ ïîäïèñü ..................................................................................131 10.1.4. Ñëó÷àéíûå äàííûå..................................................................................132 10.2. Èñïîëüçîâàíèå êðèïòîãðàôèè â ïðèëîæåíèÿõ äëÿ ñìàðò-êàðò ...................133 10.2.1. Îáåñïå÷åíèå áåçîïàñíîñòè ïðèëîæåíèé...............................................133 10.2.2. Èñïîëüçîâàíèå ñìàðò-êàðò â êà÷åñòâå çàùèùåííîãî ñðåäñòâà èäåíòèôèêàöèè........................................................................................134 10.2.3. Âûâîäû.....................................................................................................134 10.3. Êðèïòîãðàôè÷åñêèå API, ïîääåðæèâàåìûå ïëàòôîðìîé Java Card.............135 10.3.1. Ïðèíöèïû ðàçðàáîòêè............................................................................135 10.3.2. Àðõèòåêòóðà..............................................................................................135 10.3.3. Ñòðóêòóðà ïàêåòîâ...................................................................................137 10.4. Ïðèìåðû ïðîãðàìì..........................................................................................138 10.4.1. Âû÷èñëåíèå äàéäæåñòà ñîîáùåíèÿ........................................................138 10.4.2. Ñîçäàíèå êðèïòîãðàôè÷åñêîãî êëþ÷à...................................................140 10.4.3. Ñîçäàíèå è ïðîâåðêà öèôðîâîé ïîäïèñè..............................................142 10.4.4. Øèôðîâàíèå è ðàñøèôðîâêà äàííûõ ...................................................144 10.4.5. Ãåíåðàöèÿ ñëó÷àéíûõ äàííûõ ................................................................145 Ãëàâà 11. Áåçîïàñíîñòü ïëàòôîðìû Java Card..............................................................147 11.1. Ñðåäñòâà áåçîïàñíîñòè ïëàòôîðìû Java Card................................................147 11.1.1. Ñðåäñòâà áåçîïàñíîñòè ÿçûêà Java.........................................................147 11.1.2. Äîïîëíèòåëüíûå ñðåäñòâà îáåñïå÷åíèÿ áåçîïàñíîñòè ïëàòôîðìû Java Card.....................................................................................................148 11.2. Ìåõàíèçìû áåçîïàñíîñòè ïëàòôîðìû Java Card...........................................149 11.2.1. Ïðîâåðêà â ïðîöåññå êîìïèëÿöèè ........................................................149 11.2.2. Ïðîâåðêà ôàéëîâ êëàññîâ è ïðîâåðêà ñîîòâåòñòâèÿ ïîäìíîæåñòâó ÿçûêà................................................................................150 11.2.3. Ïðîâåðêà ôàéëîâ CAP è ýêñïîðòíûõ ôàéëîâ.......................................151 Ñîäåðæàíèå 9 11.2.4. Ïðîâåðêà ïðè èíñòàëëÿöèè....................................................................153 11.2.5. Êðèïòîãðàôè÷åñêàÿ çàùèòà öåïî÷êè ñîçäàíèÿ àïëåòîâ ......................155 11.2.6. Îáåñïå÷åíèå áåçîïàñíîñòè âî âðåìÿ âûïîëíåíèÿ ...............................155 11.2.7. Êðèïòîãðàôè÷åñêàÿ ïîääåðæêà ïëàòôîðìû Java Card.........................157 11.3. Çàùèòà àïëåòîâ.................................................................................................157 ×ÀÑÒÜ 3. ÐÓÊÎÂÎÄÑÒÂÎ ÄËß ÏÐÎÃÐÀÌÌÈÑÒÀ È ÏÐÈÅÌÛ ÏÐÎÃÐÀÌÌÈÐÎÂÀÍÈß...........................................................................159 Ãëàâà 12. Ïîøàãîâîå ðóêîâîäñòâî ïî ðàçðàáîòêå àïëåòà............................................160 12.1. Ïðîåêòèðîâàíèå àïëåòà...................................................................................160 12.1.1. Îïðåäåëåíèå ôóíêöèé àïëåòà ................................................................160 12.1.2. Îïðåäåëåíèå AID äëÿ àïëåòà..................................................................161 12.1.3. Îïðåäåëåíèå ñòðóêòóðû êëàññîâ è ôóíêöèé ìåòîäîâ àïëåòà...............161 12.1.4. Îïðåäåëåíèå èíòåðôåéñà ìåæäó àïëåòîì è åãî õîñò-ïðèëîæåíèåì........162 12.1.4.1. SELECT APDU...............................................................................163 12.1.4.2. VERIFY APDU...............................................................................164 12.1.4.3. CREDIT APDU..............................................................................164 12.1.4.4. DEBIT APDU.................................................................................164 12.1.4.5. GET BALANCE APDU..................................................................165 12.2. Ðàçðàáîòêà êîäà àïëåòà....................................................................................165 12.2.1. Ïðèìåð êîäà àïëåòà «ýëåêòðîííûé êîøåëåê».......................................165 12.2.2. Ðåàëèçàöèÿ êîíòðîëÿ çà îøèáêàìè â àïëåòàõ .......................................170 12.3. ×òî äàëüøå?......................................................................................................171 Ãëàâà 13. Îïòèìèçàöèÿ àïëåòîâ....................................................................................172 13.1. Îáùàÿ îïòèìèçàöèÿ äèçàéíà àïëåòà..............................................................172 13.2. Áûñòðîäåéñòâèå àïëåòà....................................................................................173 13.3. Âûçîâ ìåòîäîâ..................................................................................................173 13.4. Ñîçäàíèå îáúåêòîâ â àïëåòàõ...........................................................................173 13.5. Ïîâòîðíîå èñïîëüçîâàíèå îáúåêòîâ ..............................................................174 13.6. Óñòðàíåíèå èçáûòî÷íîãî êîäà........................................................................175 13.7. Äîñòóï ê ìàññèâàì...........................................................................................176 13.8. Ñðàâíåíèå îïåðàòîðîâ switch è if-else....................................................177 13.9. Àðèôìåòè÷åñêèå îïåðàòîðû ...........................................................................179 13.10. Îïòèìèçàöèÿ ïåðåìåííûõ â àïëåòàõ............................................................179 Ãëàâà 14. Ðàáîòà ñ òèïîì äàííûõ int...........................................................................181 14.1. 32-ðàçðÿäíûå àðèôìåòè÷åñêèå îïåðàöèè......................................................181 14.2. Ðàçìåðû è èíäåêñû ìàññèâà............................................................................191 14.3. Õðàíåíèå è âû÷èñëåíèå äàííûõ òèïà int.....................................................191 14.4. Âûâîäû .............................................................................................................195 ×ÀÑÒÜ 4. ÏÐÈËÎÆÅÍÈß...........................................................................................197 Ïðèëîæåíèå A. Ïîäìíîæåñòâî ÿçûêà Java Card..........................................................198 Ïðèëîæåíèå B. Èíòåðôåéñ ïðèêëàäíîãî ïðîãðàììèðîâàíèÿ Java Card 2.1.............205 Ãëîññàðèé........................................................................................................................338 Áèáëèîãðàôèÿ .................................................................................................................341 Предисловие Êíèãà, êîòîðóþ âû äåðæèòå â ðóêàõ, îëèöåòâîðÿåò âàæíóþ âåõó â èñòîðèè ñìàðò- êàðò. Îíà âîïëîùàåò êàðäèíàëüíûå èçìåíåíèÿ â îòðàñëè: ñìàðò-êàðòû ïåðåñòà- ëè áûòü çàêðûòûìè óçêîñïåöèàëèçèðîâàííûìè óñòðîéñòâàìè, êîòîðûå ìîãëè âûïóñêàòü è ïðîãðàììèðîâàòü òîëüêî íåìíîãî÷èñëåííûå òåõíè÷åñêèå «ãóðó». Îíè ïðåâðàòèëèñü â ïîëíîöåííûå ïðîãðàììèðóåìûå îáúåêòû, êîòîðûå ìîæíî ëåãêî èíòåãðèðîâàòü â èíôîðìàöèîííûå ñèñòåìû ñ ïîìîùüþ îáùåäîñòóïíûõ èíòåð- ôåéñîâ è øèðîêî ðàñïðîñòðàíåííûõ ÿçûêîâ ïðîãðàììèðîâàíèÿ. È ÷òî æå ýòî äàëî? Èìåþò ëè âñå ýòè ïåðåìåíû êàêîå-òî çíà÷åíèå äëÿ ÷åëîâå- ÷åñòâà èëè òîëüêî äëÿ îòðàñëè âûñîêèõ òåõíîëîãèé? Íà ñàìîì äåëå òåïåðü ñìàðò- êàðòû – ýòî íå ïðîñòî âû÷èñëèòåëüíûå ïëàòôîðìû. Óæå äîêàçàíà èõ íàäåæíîñòü è áåçîïàñíîñòü.  ñìàðò-êàðòàõ ìîæåò õðàíèòüñÿ êëþ÷ äëÿ äîñòóïà ê âàøåìó áàí- êîâñêîìó ñ÷åòó, âàø ïàðîëü äëÿ ïðîñìîòðà ïëàòíûõ òåëåêàíàëîâ è äàæå âàøà èñ- òîðèÿ áîëåçíè. Íî äëÿ òîãî ÷òîáû ñìàðò-êàðòû ñòàëè íåîòúåìëåìûì àòðèáóòîì íàøåé æèç- íè, íóæíî ðåøèòü íåêîòîðûå ïðîáëåìû: îáåñïå÷èòü èõ áûñòðîå ðàñïðîñòðàíå- íèå, ñîçäàòü óñëîâèÿ äëÿ ïîÿâëåíèÿ íîâûõ ïðèâëåêàòåëüíûõ ìîäåëåé èñïîëüçî- âàíèÿ, èäòè â íîãó ñ áûñòðûì ðàçâèòèåì Èíòåðíåòà è ïðè ýòîì îáåñïå÷èòü íåîá- õîäèìûé óðîâåíü çàùèòû. Êëþ÷ ê ðàçðåøåíèþ ýòèõ ïðîáëåì – ÿçûê ïðîãðàììèðîâàíèÿ Java™ – õîðî- øî çàùèùåííàÿ è íàäåæíàÿ îáúåêòíî-îðèåíòèðîâàííàÿ ïëàòôîðìà, êîòîðàÿ óñ- ïåøíî ïðèìåíÿåòñÿ äëÿ ñîçäàíèÿ èíòåðíåò-ïðèëîæåíèé. Ýòè êà÷åñòâà îñîáåííî âàæíû äëÿ ñìàðò-êàðò, âåäü îíè âñå ÷àùå èñïîëüçóþòñÿ â ìàññîâûõ ñåòåâûõ ñðå- äàõ. Ïëàòôîðìà Java îáåñïå÷èâàåò íåîáõîäèìûé óðîâåíü áåçîïàñíîñòè è íàäåæ- íîñòè áëàãîäàðÿ òîìó, ÷òî â íåé ðåàëèçîâàíû òðè âàæíåéøèõ ïðèíöèïà: • Ïðîñòîòà: ïðîãðàììèñòû ìîãóò î÷åíü áûñòðî îñâîèòü ýòîò ÿçûê, à îòëà- äèòü ïðîãðàììó Java ãîðàçäî ïðîùå è áûñòðåå, ÷åì ïðîãðàììû äëÿ äðóãèõ ïëàòôîðì. • Èíôîðìàöèîííàÿ áåçîïàñíîñòü: ÿçûê Java ñîäåðæèò ñðåäñòâà îáåñïå÷åíèÿ áåçîïàñíîñòè êàê íà óðîâíå òèïîâ äàííûõ, òàê è íà óðîâíå äîñòóïà ê ïàìÿ- òè. Ïëàòôîðìà Java èìååò äîñòàòî÷íî ðàçâèòûå ñðåäñòâà çàùèòû ïî ñðàâ- íåíèþ ñ äðóãèìè øèðîêî ðàñïðîñòðàíåííûìè ÿçûêàìè ïðîãðàììèðîâà- íèÿ. Ýòè ñðåäñòâà ïîçâîëÿþò óñïåøíî áîðîòüñÿ ñ íåñàíêöèîíèðîâàííûì äîñòóïîì ê äàííûì è çëîóìûøëåííûìè âòîðæåíèÿìè. • Çàùèùåííîñòü: â ïëàòôîðìå ðåàëèçîâàí âñòðîåííûé çàùèùåííûé ìåõàíèçì çàãðóçêè, êîòîðûé ïîçâîëÿåò óñòàíàâëèâàòü ðàçëè÷íûå óðîâíè äîâåðèÿ ïðè èñïîëüçîâàíèè ïðîãðàìì èç ìíîãî÷èñëåííûõ âíåøíèõ èñòî÷íèêîâ. Ïðîèçâîäèòåëè ñìàðò-êàðò óæå äàâíî èñêàëè çàñëóæèâàþùóþ äîâåðèÿ è íà- äåæíóþ ïðîãðàììíóþ ïëàòôîðìó. Íî ðåàëüíûé êîììåð÷åñêèé ñïðîñ íà èíòåë- ëåêòóàëüíûå ñìàðò-êàðòû, ïîäõîäÿùèå äëÿ îðãàíèçàöèè äîñòóïà ê ñåòè, ïîæà- ëóé, âïåðâûå âîçíèê â 1988 ãîäó. Òîãäà êîìïàíèÿ News Group çàïóñêàëà â Âåëè- êîáðèòàíèè ñâîé ïðîåêò BSkyB (êîòîðûé ïîçæå ïîëó÷èë íàçâàíèå SkyTV) – èí- íîâàöèîííóþ ñèñòåìó ïëàòíîãî ñïóòíèêîâîãî òåëåâèäåíèÿ. Äëÿ åãî ðåàëèçàöèè