diff --git a/.gitmodules b/.gitmodules index 550013b..f93dff6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,15 @@ path = npa/src/opensc url = git://github.com/OpenSC/OpenSC.git ignore = dirty +[submodule "ACardEmulator/app/src/main/external/ykneo-openpgp"] + path = ACardEmulator/app/src/main/external/ykneo-openpgp + url = https://github.com/Yubico/ykneo-openpgp.git +[submodule "ACardEmulator/app/src/main/external/ykneo-oath"] + path = ACardEmulator/app/src/main/external/ykneo-oath + url = https://github.com/Yubico/ykneo-oath.git +[submodule "ACardEmulator/app/src/main/external/IsoApplet"] + path = ACardEmulator/app/src/main/external/IsoApplet + url = https://github.com/frankmorgner/IsoApplet.git +[submodule "ACardEmulator/app/src/main/external/jcardsim"] + path = ACardEmulator/app/src/main/external/jcardsim + url = https://github.com/frankmorgner/jcardsim.git diff --git a/ACardEmulator/.gitignore b/ACardEmulator/.gitignore new file mode 100644 index 0000000..afbdab3 --- /dev/null +++ b/ACardEmulator/.gitignore @@ -0,0 +1,6 @@ +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build diff --git a/ACardEmulator/.idea/compiler.xml b/ACardEmulator/.idea/compiler.xml new file mode 100644 index 0000000..217af47 --- /dev/null +++ b/ACardEmulator/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/ACardEmulator/.idea/copyright/profiles_settings.xml b/ACardEmulator/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/ACardEmulator/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/ACardEmulator/.idea/encodings.xml b/ACardEmulator/.idea/encodings.xml new file mode 100644 index 0000000..e206d70 --- /dev/null +++ b/ACardEmulator/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/ACardEmulator/.idea/gradle.xml b/ACardEmulator/.idea/gradle.xml new file mode 100644 index 0000000..fe865d3 --- /dev/null +++ b/ACardEmulator/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + diff --git a/ACardEmulator/.idea/misc.xml b/ACardEmulator/.idea/misc.xml new file mode 100644 index 0000000..c6052d1 --- /dev/null +++ b/ACardEmulator/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/ACardEmulator/.idea/modules.xml b/ACardEmulator/.idea/modules.xml new file mode 100644 index 0000000..d7d75bd --- /dev/null +++ b/ACardEmulator/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/ACardEmulator/.idea/scopes/scope_settings.xml b/ACardEmulator/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..922003b --- /dev/null +++ b/ACardEmulator/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/ACardEmulator/.idea/vcs.xml b/ACardEmulator/.idea/vcs.xml new file mode 100644 index 0000000..21cbaa6 --- /dev/null +++ b/ACardEmulator/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ACardEmulator/ACardEmulator.iml b/ACardEmulator/ACardEmulator.iml new file mode 100644 index 0000000..0bb6048 --- /dev/null +++ b/ACardEmulator/ACardEmulator.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + diff --git a/ACardEmulator/COPYING b/ACardEmulator/COPYING new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/ACardEmulator/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/ACardEmulator/app/.gitignore b/ACardEmulator/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/ACardEmulator/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/ACardEmulator/app/app.iml b/ACardEmulator/app/app.iml new file mode 100644 index 0000000..bf56032 --- /dev/null +++ b/ACardEmulator/app/app.iml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ACardEmulator/app/build.gradle b/ACardEmulator/app/build.gradle new file mode 100644 index 0000000..bc7a5ab --- /dev/null +++ b/ACardEmulator/app/build.gradle @@ -0,0 +1,34 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 21 + buildToolsVersion "21.1.2" + + defaultConfig { + applicationId "com.vsmartcard.acardemulator" + minSdkVersion 19 + targetSdkVersion 21 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + sourceSets { + main.java.srcDirs += 'src/main/external/jcardsim/src/main/java' + main.java.exclude('**/APDUScriptTool.java') + main.java.srcDirs += 'src/main/external/IsoApplet/src' + main.java.srcDirs += 'src/main/external/android-scio/src/main' + main.java.srcDirs += 'src/main/external/ykneo-openpgp/applet/src' + main.java.srcDirs += 'src/main/external/ykneo-oath/applet/src' + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:appcompat-v7:21.0.3' + compile group: 'com.madgag.spongycastle', name: 'core', version: '1.51.0.0' +} diff --git a/ACardEmulator/app/src/main/AndroidManifest.xml b/ACardEmulator/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..d295d18 --- /dev/null +++ b/ACardEmulator/app/src/main/AndroidManifest.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ACardEmulator/app/src/main/external/IsoApplet b/ACardEmulator/app/src/main/external/IsoApplet new file mode 160000 index 0000000..06a68a9 --- /dev/null +++ b/ACardEmulator/app/src/main/external/IsoApplet @@ -0,0 +1 @@ +Subproject commit 06a68a9f59a7a81bb6d0e6e6dbaf3264334c9f43 diff --git a/ACardEmulator/app/src/main/external/android-scio/pom.xml b/ACardEmulator/app/src/main/external/android-scio/pom.xml new file mode 100644 index 0000000..eba67fa --- /dev/null +++ b/ACardEmulator/app/src/main/external/android-scio/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + + + org.openecard.ifd + scio-backend + 1.1.0-SNAPSHOT + + + org.openecard.ifd.scio-backend + android-scio + jar + SmartcardIO for Android + + diff --git a/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/ATR.java b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/ATR.java new file mode 100644 index 0000000..d841458 --- /dev/null +++ b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/ATR.java @@ -0,0 +1,165 @@ +/* + * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package javax.smartcardio; + +import java.util.*; + +/** + * A Smart Card's answer-to-reset bytes. A Card's ATR object can be obtained + * by calling {@linkplain Card#getATR}. + * This class does not attempt to verify that the ATR encodes a semantically + * valid structure. + * + *

Instances of this class are immutable. Where data is passed in or out + * via byte arrays, defensive cloning is performed. + * + * @see Card#getATR + * + * @since 1.6 + * @author Andreas Sterbenz + * @author JSR 268 Expert Group + */ +public final class ATR implements java.io.Serializable { + + private static final long serialVersionUID = 6695383790847736493L; + + private byte[] atr; + + private transient int startHistorical, nHistorical; + + /** + * Constructs an ATR from a byte array. + * + * @param atr the byte array containing the answer-to-reset bytes + * @throws NullPointerException if atr is null + */ + public ATR(byte[] atr) { + this.atr = atr.clone(); + parse(); + } + + private void parse() { + if (atr.length < 2) { + return; + } + if ((atr[0] != 0x3b) && (atr[0] != 0x3f)) { + return; + } + int t0 = (atr[1] & 0xf0) >> 4; + int n = atr[1] & 0xf; + int i = 2; + while ((t0 != 0) && (i < atr.length)) { + if ((t0 & 1) != 0) { + i++; + } + if ((t0 & 2) != 0) { + i++; + } + if ((t0 & 4) != 0) { + i++; + } + if ((t0 & 8) != 0) { + if (i >= atr.length) { + return; + } + t0 = (atr[i++] & 0xf0) >> 4; + } else { + t0 = 0; + } + } + int k = i + n; + if ((k == atr.length) || (k == atr.length - 1)) { + startHistorical = i; + nHistorical = n; + } + } + + /** + * Returns a copy of the bytes in this ATR. + * + * @return a copy of the bytes in this ATR. + */ + public byte[] getBytes() { + return atr.clone(); + } + + /** + * Returns a copy of the historical bytes in this ATR. + * If this ATR does not contain historical bytes, an array of length + * zero is returned. + * + * @return a copy of the historical bytes in this ATR. + */ + public byte[] getHistoricalBytes() { + byte[] b = new byte[nHistorical]; + System.arraycopy(atr, startHistorical, b, 0, nHistorical); + return b; + } + + /** + * Returns a string representation of this ATR. + * + * @return a String representation of this ATR. + */ + public String toString() { + return "ATR: " + atr.length + " bytes"; + } + + /** + * Compares the specified object with this ATR for equality. + * Returns true if the given object is also an ATR and its bytes are + * identical to the bytes in this ATR. + * + * @param obj the object to be compared for equality with this ATR + * @return true if the specified object is equal to this ATR + */ + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof ATR == false) { + return false; + } + ATR other = (ATR)obj; + return Arrays.equals(this.atr, other.atr); + } + + /** + * Returns the hash code value for this ATR. + * + * @return the hash code value for this ATR. + */ + public int hashCode() { + return Arrays.hashCode(atr); + } + + private void readObject(java.io.ObjectInputStream in) + throws java.io.IOException, ClassNotFoundException { + atr = (byte[])in.readUnshared(); + parse(); + } + +} diff --git a/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/Card.java b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/Card.java new file mode 100644 index 0000000..3bf97ad --- /dev/null +++ b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/Card.java @@ -0,0 +1,167 @@ +/* + * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package javax.smartcardio; + +import java.nio.ByteBuffer; + +/** + * A Smart Card with which a connection has been established. Card objects + * are obtained by calling {@link CardTerminal#connect CardTerminal.connect()}. + * + * @see CardTerminal + * + * @since 1.6 + * @author Andreas Sterbenz + * @author JSR 268 Expert Group +*/ +public abstract class Card { + + /** + * Constructs a new Card object. + * + *

This constructor is called by subclasses only. Application should + * call the {@linkplain CardTerminal#connect CardTerminal.connect()} + * method to obtain a Card + * object. + */ + protected Card() { + // empty + } + + /** + * Returns the ATR of this card. + * + * @return the ATR of this card. + */ + public abstract ATR getATR(); + + /** + * Returns the protocol in use for this card. + * + * @return the protocol in use for this card, for example "T=0" or "T=1" + */ + public abstract String getProtocol(); + + /** + * Returns the CardChannel for the basic logical channel. The basic + * logical channel has a channel number of 0. + * + * @throws SecurityException if a SecurityManager exists and the + * caller does not have the required + * {@linkplain CardPermission permission} + * @throws IllegalStateException if this card object has been disposed of + * via the {@linkplain #disconnect disconnect()} method + */ + public abstract CardChannel getBasicChannel(); + + /** + * Opens a new logical channel to the card and returns it. The channel is + * opened by issuing a MANAGE CHANNEL command that should use + * the format [00 70 00 00 01]. + * + * @throws SecurityException if a SecurityManager exists and the + * caller does not have the required + * {@linkplain CardPermission permission} + * @throws CardException is a new logical channel could not be opened + * @throws IllegalStateException if this card object has been disposed of + * via the {@linkplain #disconnect disconnect()} method + */ + public abstract CardChannel openLogicalChannel() throws CardException; + + /** + * Requests exclusive access to this card. + * + *

Once a thread has invoked beginExclusive, only this + * thread is allowed to communicate with this card until it calls + * endExclusive. Other threads attempting communication + * will receive a CardException. + * + *

Applications have to ensure that exclusive access is correctly + * released. This can be achieved by executing + * the beginExclusive() and endExclusive calls + * in a try ... finally block. + * + * @throws SecurityException if a SecurityManager exists and the + * caller does not have the required + * {@linkplain CardPermission permission} + * @throws CardException if exclusive access has already been set + * or if exclusive access could not be established + * @throws IllegalStateException if this card object has been disposed of + * via the {@linkplain #disconnect disconnect()} method + */ + public abstract void beginExclusive() throws CardException; + + /** + * Releases the exclusive access previously established using + * beginExclusive. + * + * @throws SecurityException if a SecurityManager exists and the + * caller does not have the required + * {@linkplain CardPermission permission} + * @throws IllegalStateException if the active Thread does not currently have + * exclusive access to this card or + * if this card object has been disposed of + * via the {@linkplain #disconnect disconnect()} method + * @throws CardException if the operation failed + */ + public abstract void endExclusive() throws CardException; + + /** + * Transmits a control command to the terminal device. + * + *

This can be used to, for example, control terminal functions like + * a built-in PIN pad or biometrics. + * + * @param controlCode the control code of the command + * @param command the command data + * + * @throws SecurityException if a SecurityManager exists and the + * caller does not have the required + * {@linkplain CardPermission permission} + * @throws NullPointerException if command is null + * @throws CardException if the card operation failed + * @throws IllegalStateException if this card object has been disposed of + * via the {@linkplain #disconnect disconnect()} method + */ + public abstract byte[] transmitControlCommand(int controlCode, + byte[] command) throws CardException; + + /** + * Disconnects the connection with this card. After this method returns, + * calling methods on this object or in CardChannels associated with this + * object that require interaction with the card will raise an + * IllegalStateException. + * + * @param reset whether to reset the card after disconnecting. + * + * @throws CardException if the card operation failed + * @throws SecurityException if a SecurityManager exists and the + * caller does not have the required + * {@linkplain CardPermission permission} + */ + public abstract void disconnect(boolean reset) throws CardException; + +} diff --git a/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardChannel.java b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardChannel.java new file mode 100644 index 0000000..5b1c6c2 --- /dev/null +++ b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardChannel.java @@ -0,0 +1,184 @@ +/* + * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package javax.smartcardio; + +import java.nio.*; + +/** + * A logical channel connection to a Smart Card. It is used to exchange APDUs + * with a Smart Card. + * A CardChannel object can be obtained by calling the method + * {@linkplain Card#getBasicChannel} or {@linkplain Card#openLogicalChannel}. + * + * @see Card + * @see CommandAPDU + * @see ResponseAPDU + * + * @since 1.6 + * @author Andreas Sterbenz + * @author JSR 268 Expert Group + */ +public abstract class CardChannel { + + /** + * Constructs a new CardChannel object. + * + *

This constructor is called by subclasses only. Application should + * call the {@linkplain Card#getBasicChannel} and + * {@linkplain Card#openLogicalChannel} methods to obtain a CardChannel + * object. + */ + protected CardChannel() { + // empty + } + + /** + * Returns the Card this channel is associated with. + * + * @return the Card this channel is associated with + */ + public abstract Card getCard(); + + /** + * Returns the channel number of this CardChannel. A channel number of + * 0 indicates the basic logical channel. + * + * @return the channel number of this CardChannel. + * + * @throws IllegalStateException if this channel has been + * {@linkplain #close closed} or if the corresponding Card has been + * {@linkplain Card#disconnect disconnected}. + */ + public abstract int getChannelNumber(); + + /** + * Transmits the specified command APDU to the Smart Card and returns the + * response APDU. + * + *

The CLA byte of the command APDU is automatically adjusted to + * match the channel number of this CardChannel. + * + *

Note that this method cannot be used to transmit + * MANAGE CHANNEL APDUs. Logical channels should be managed + * using the {@linkplain Card#openLogicalChannel} and {@linkplain + * CardChannel#close CardChannel.close()} methods. + * + *

Implementations should transparently handle artifacts + * of the transmission protocol. + * For example, when using the T=0 protocol, the following processing + * should occur as described in ISO/IEC 7816-4: + * + *

    + *
  • if the response APDU has an SW1 of 61, the + * implementation should issue a GET RESPONSE command + * using SW2 as the Lefield. + * This process is repeated as long as an SW1 of 61 is + * received. The response body of these exchanges is concatenated + * to form the final response body. + * + *

  • if the response APDU is 6C XX, the implementation + * should reissue the command using XX as the + * Le field. + *

+ * + *

The ResponseAPDU returned by this method is the result + * after this processing has been performed. + * + * @param command the command APDU + * @return the response APDU received from the card + * + * @throws IllegalStateException if this channel has been + * {@linkplain #close closed} or if the corresponding Card has been + * {@linkplain Card#disconnect disconnected}. + * @throws IllegalArgumentException if the APDU encodes a + * MANAGE CHANNEL command + * @throws NullPointerException if command is null + * @throws CardException if the card operation failed + */ + public abstract ResponseAPDU transmit(CommandAPDU command) throws CardException; + + /** + * Transmits the command APDU stored in the command ByteBuffer and receives + * the reponse APDU in the response ByteBuffer. + * + *

The command buffer must contain valid command APDU data starting + * at command.position() and the APDU must be + * command.remaining() bytes long. + * Upon return, the command buffer's position will be equal + * to its limit; its limit will not have changed. The output buffer + * will have received the response APDU bytes. Its position will have + * advanced by the number of bytes received, which is also the return + * value of this method. + * + *

The CLA byte of the command APDU is automatically adjusted to + * match the channel number of this CardChannel. + * + *

Note that this method cannot be used to transmit + * MANAGE CHANNEL APDUs. Logical channels should be managed + * using the {@linkplain Card#openLogicalChannel} and {@linkplain + * CardChannel#close CardChannel.close()} methods. + * + *

See {@linkplain #transmit transmit()} for a discussion of the handling + * of response APDUs with the SW1 values 61 or 6C. + * + * @param command the buffer containing the command APDU + * @param response the buffer that shall receive the response APDU from + * the card + * @return the length of the received response APDU + * + * @throws IllegalStateException if this channel has been + * {@linkplain #close closed} or if the corresponding Card has been + * {@linkplain Card#disconnect disconnected}. + * @throws NullPointerException if command or response is null + * @throws ReadOnlyBufferException if the response buffer is read-only + * @throws IllegalArgumentException if command and response are the + * same object, if response may not have + * sufficient space to receive the response APDU + * or if the APDU encodes a MANAGE CHANNEL command + * @throws CardException if the card operation failed + */ + public abstract int transmit(ByteBuffer command, ByteBuffer response) + throws CardException; + + /** + * Closes this CardChannel. The logical channel is closed by issuing + * a MANAGE CHANNEL command that should use the format + * [xx 70 80 0n] where n is the channel number + * of this channel and xx is the CLA + * byte that encodes this logical channel and has all other bits set to 0. + * After this method returns, calling other + * methods in this class will raise an IllegalStateException. + * + *

Note that the basic logical channel cannot be closed using this + * method. It can be closed by calling {@link Card#disconnect}. + * + * @throws CardException if the card operation failed + * @throws IllegalStateException if this CardChannel represents a + * connection the basic logical channel + */ + public abstract void close() throws CardException; + +} diff --git a/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardException.java b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardException.java new file mode 100644 index 0000000..763c8a3 --- /dev/null +++ b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardException.java @@ -0,0 +1,68 @@ +/* + * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package javax.smartcardio; + +/** + * Exception for errors that occur during communication with the + * Smart Card stack or the card itself. + * + * @since 1.6 + * @author Andreas Sterbenz + * @author JSR 268 Expert Group + */ +public class CardException extends Exception { + + private static final long serialVersionUID = 7787607144922050628L; + + /** + * Constructs a new CardException with the specified detail message. + * + * @param message the detail message + */ + public CardException(String message) { + super(message); + } + + /** + * Constructs a new CardException with the specified cause and a detail message + * of (cause==null ? null : cause.toString()). + * + * @param cause the cause of this exception or null + */ + public CardException(Throwable cause) { + super(cause); + } + + /** + * Constructs a new CardException with the specified detail message and cause. + * + * @param message the detail message + * @param cause the cause of this exception or null + */ + public CardException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardNotPresentException.java b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardNotPresentException.java new file mode 100644 index 0000000..6a22625 --- /dev/null +++ b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardNotPresentException.java @@ -0,0 +1,68 @@ +/* + * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package javax.smartcardio; + +/** + * Exception thrown when an application tries to establish a connection with a + * terminal that has no card present. + * + * @since 1.6 + * @author Andreas Sterbenz + * @author JSR 268 Expert Group + */ +public class CardNotPresentException extends CardException { + + private final static long serialVersionUID = 1346879911706545215L; + + /** + * Constructs a new CardNotPresentException with the specified detail message. + * + * @param message the detail message + */ + public CardNotPresentException(String message) { + super(message); + } + + /** + * Constructs a new CardNotPresentException with the specified cause and a detail message + * of (cause==null ? null : cause.toString()). + * + * @param cause the cause of this exception or null + */ + public CardNotPresentException(Throwable cause) { + super(cause); + } + + /** + * Constructs a new CardNotPresentException with the specified detail message and cause. + * + * @param message the detail message + * @param cause the cause of this exception or null + */ + public CardNotPresentException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardPermission.java b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardPermission.java new file mode 100644 index 0000000..aa294b9 --- /dev/null +++ b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardPermission.java @@ -0,0 +1,301 @@ +/* + * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package javax.smartcardio; + +import java.io.*; + +import java.security.Permission; + +/** + * A permission for Smart Card operations. A CardPermission consists of the + * name of the card terminal the permission applies to and a set of actions + * that are valid for that terminal. + * + *

A CardPermission with a name of * applies to all + * card terminals. The actions string is a comma separated list of the actions + * listed below, or * to signify "all actions." + * + *

Individual actions are: + *

+ *
connect + *
connect to a card using + * {@linkplain CardTerminal#connect CardTerminal.connect()} + * + *
reset + *
reset the card using {@linkplain Card#disconnect Card.disconnect(true)} + * + *
exclusive + *
establish exclusive access to a card using + * {@linkplain Card#beginExclusive} and {@linkplain Card#endExclusive + * endExclusive()} + * + *
transmitControl + *
transmit a control command using + * {@linkplain Card#transmitControlCommand Card.transmitControlCommand()} + * + *
getBasicChannel + *
obtain the basic logical channel using + * {@linkplain Card#getBasicChannel} + * + *
openLogicalChannel + *
open a new logical channel using + * {@linkplain Card#openLogicalChannel} + * + *
+ * + * @since 1.6 + * @author Andreas Sterbenz + * @author JSR 268 Expert Group + */ +public class CardPermission extends Permission { + + private static final long serialVersionUID = 7146787880530705613L; + + private final static int A_CONNECT = 0x01; + private final static int A_EXCLUSIVE = 0x02; + private final static int A_GET_BASIC_CHANNEL = 0x04; + private final static int A_OPEN_LOGICAL_CHANNEL = 0x08; + private final static int A_RESET = 0x10; + private final static int A_TRANSMIT_CONTROL = 0x20; + + // sum of all the actions above + private final static int A_ALL = 0x3f; + + private final static int[] ARRAY_MASKS = { + A_ALL, + A_CONNECT, + A_EXCLUSIVE, + A_GET_BASIC_CHANNEL, + A_OPEN_LOGICAL_CHANNEL, + A_RESET, + A_TRANSMIT_CONTROL, + }; + + private final static String S_CONNECT = "connect"; + private final static String S_EXCLUSIVE = "exclusive"; + private final static String S_GET_BASIC_CHANNEL = "getBasicChannel"; + private final static String S_OPEN_LOGICAL_CHANNEL = "openLogicalChannel"; + private final static String S_RESET = "reset"; + private final static String S_TRANSMIT_CONTROL = "transmitControl"; + + private final static String S_ALL = "*"; + + private final static String[] ARRAY_STRINGS = { + S_ALL, + S_CONNECT, + S_EXCLUSIVE, + S_GET_BASIC_CHANNEL, + S_OPEN_LOGICAL_CHANNEL, + S_RESET, + S_TRANSMIT_CONTROL, + }; + + private transient int mask; + + /** + * @serial + */ + private volatile String actions; + + /** + * Constructs a new CardPermission with the specified actions. + * terminalName is the name of a CardTerminal or * + * if this permission applies to all terminals. actions + * contains a comma-separated list of the individual actions + * or * to signify all actions. For more information, + * see the documentation at the top of this {@linkplain CardPermission + * class}. + * + * @param terminalName the name of the card terminal, or * + * @param actions the action string (or null if the set of permitted + * actions is empty) + * + * @throws NullPointerException if terminalName is null + * @throws IllegalArgumentException if actions is an invalid actions + * specification + */ + public CardPermission(String terminalName, String actions) { + super(terminalName); + if (terminalName == null) { + throw new NullPointerException(); + } + mask = getMask(actions); + } + + private static int getMask(String actions) { + if ((actions == null) || (actions.length() == 0)) { + throw new IllegalArgumentException("actions must not be empty"); + } + + // try exact matches for simple actions first + for (int i = 0; i < ARRAY_STRINGS.length; i++) { + if (actions == ARRAY_STRINGS[i]) { + return ARRAY_MASKS[i]; + } + } + + if (actions.endsWith(",")) { + throw new IllegalArgumentException("Invalid actions: '" + actions + "'"); + } + int mask = 0; + String[] split = actions.split(","); + outer: + for (String s : split) { + for (int i = 0; i < ARRAY_STRINGS.length; i++) { + if (ARRAY_STRINGS[i].equalsIgnoreCase(s)) { + mask |= ARRAY_MASKS[i]; + continue outer; + } + } + throw new IllegalArgumentException("Invalid action: '" + s + "'"); + } + + return mask; + } + + private static String getActions(int mask) { + if (mask == A_ALL) { + return S_ALL; + } + boolean first = true; + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < ARRAY_MASKS.length; i++) { + int action = ARRAY_MASKS[i]; + if ((mask & action) == action) { + if (first == false) { + sb.append(","); + } else { + first = false; + } + sb.append(ARRAY_STRINGS[i]); + } + } + return sb.toString(); + } + + + /** + * Returns the canonical string representation of the actions. + * It is * to signify all actions defined by this class or + * the string concatenation of the comma-separated, + * lexicographically sorted list of individual actions. + * + * @return the canonical string representation of the actions. + */ + public String getActions() { + if (actions == null) { + actions = getActions(mask); + } + return actions; + } + + /** + * Checks if this CardPermission object implies the specified permission. + * That is the case, if and only if + *
    + *
  • permission is an instance of CardPermission,

    + *
  • permission's actions are a proper subset of this + * object's actions, and

    + *
  • this object's getName() method is either + * * or equal to permission's name. + *

    + *
+ * + * @param permission the permission to check against + * @return true if and only if this CardPermission object implies the + * specified permission. + */ + public boolean implies(Permission permission) { + if (permission instanceof CardPermission == false) { + return false; + } + CardPermission other = (CardPermission)permission; + if ((this.mask & other.mask) != other.mask) { + return false; + } + String thisName = getName(); + if (thisName.equals("*")) { + return true; + } + if (thisName.equals(other.getName())) { + return true; + } + return false; + } + + /** + * Compares the specified object with this CardPermission for equality. + * This CardPermission is equal to another Object object, if + * and only if + *
    + *
  • object is an instance of CardPermission,

    + *
  • this.getName() is equal to + * ((CardPermission)object).getName(), and

    + *
  • this.getActions() is equal to + * ((CardPermission)object).getActions().

    + *
+ * + * @param obj the object to be compared for equality with this CardPermission + * @return true if and only if the specified object is equal to this + * CardPermission + */ + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof CardPermission == false) { + return false; + } + CardPermission other = (CardPermission)obj; + return this.getName().equals(other.getName()) && (this.mask == other.mask); + } + + /** + * Returns the hash code value for this CardPermission object. + * + * @return the hash code value for this CardPermission object. + */ + public int hashCode() { + return getName().hashCode() + 31 * mask; + } + + private void writeObject(ObjectOutputStream s) throws IOException { + // Write out the actions. The superclass takes care of the name. + // Call getActions to make sure actions field is initialized + if (actions == null) { + getActions(); + } + s.defaultWriteObject(); + } + + private void readObject(ObjectInputStream s) + throws IOException, ClassNotFoundException { + // Read in the actions, then restore the mask. + s.defaultReadObject(); + mask = getMask(actions); + } + +} diff --git a/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardTerminal.java b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardTerminal.java new file mode 100644 index 0000000..591023a --- /dev/null +++ b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardTerminal.java @@ -0,0 +1,134 @@ +/* + * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package javax.smartcardio; + +import java.util.*; + +/** + * A Smart Card terminal, sometimes refered to as a Smart Card Reader. + * A CardTerminal object can be obtained by calling + * {@linkplain CardTerminals#list} + * or {@linkplain CardTerminals#getTerminal CardTerminals.getTerminal()}. + * + *

Note that physical card readers with slots for multiple cards are + * represented by one CardTerminal object per such slot. + * + * @see CardTerminals + * @see TerminalFactory + * + * @since 1.6 + * @author Andreas Sterbenz + * @author JSR 268 Expert Group + */ +public abstract class CardTerminal { + + /** + * Constructs a new CardTerminal object. + * + *

This constructor is called by subclasses only. Application should + * call {@linkplain CardTerminals#list list()} + * or {@linkplain CardTerminals#getTerminal getTerminal()} + * to obtain a CardTerminal object. + */ + protected CardTerminal() { + // empty + } + + /** + * Returns the unique name of this terminal. + * + * @return the unique name of this terminal. + */ + public abstract String getName(); + + /** + * Establishes a connection to the card. + * If a connection has previously established using + * the specified protocol, this method returns the same Card object as + * the previous call. + * + * @param protocol the protocol to use ("T=0", "T=1", or "T=CL"), or "*" to + * connect using any available protocol. + * + * @throws NullPointerException if protocol is null + * @throws IllegalArgumentException if protocol is an invalid protocol + * specification + * @throws CardNotPresentException if no card is present in this terminal + * @throws CardException if a connection could not be established + * using the specified protocol or if a connection has previously been + * established using a different protocol + * @throws SecurityException if a SecurityManager exists and the + * caller does not have the required + * {@linkplain CardPermission permission} + */ + public abstract Card connect(String protocol) throws CardException; + + /** + * Returns whether a card is present in this terminal. + * + * @return whether a card is present in this terminal. + * + * @throws CardException if the status could not be determined + */ + public abstract boolean isCardPresent() throws CardException; + + /** + * Waits until a card is present in this terminal or the timeout + * expires. If the method returns due to an expired timeout, it returns + * false. Otherwise it return true. + * + *

If a card is present in this terminal when this + * method is called, it returns immediately. + * + * @param timeout if positive, block for up to timeout + * milliseconds; if zero, block indefinitely; must not be negative + * @return false if the method returns due to an expired timeout, + * true otherwise. + * + * @throws IllegalArgumentException if timeout is negative + * @throws CardException if the operation failed + */ + public abstract boolean waitForCardPresent(long timeout) throws CardException; + + /** + * Waits until a card is absent in this terminal or the timeout + * expires. If the method returns due to an expired timeout, it returns + * false. Otherwise it return true. + * + *

If no card is present in this terminal when this + * method is called, it returns immediately. + * + * @param timeout if positive, block for up to timeout + * milliseconds; if zero, block indefinitely; must not be negative + * @return false if the method returns due to an expired timeout, + * true otherwise. + * + * @throws IllegalArgumentException if timeout is negative + * @throws CardException if the operation failed + */ + public abstract boolean waitForCardAbsent(long timeout) throws CardException; + +} diff --git a/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardTerminals.java b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardTerminals.java new file mode 100644 index 0000000..38a10fa --- /dev/null +++ b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CardTerminals.java @@ -0,0 +1,219 @@ +/* + * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package javax.smartcardio; + +import java.util.*; + +/** + * The set of terminals supported by a TerminalFactory. + * This class allows applications to enumerate the available CardTerminals, + * obtain a specific CardTerminal, or wait for the insertion or removal of + * cards. + * + *

This class is multi-threading safe and can be used by multiple + * threads concurrently. However, this object keeps track of the card + * presence state of each of its terminals. Multiple objects should be used + * if independent calls to {@linkplain #waitForChange} are required. + * + *

Applications can obtain instances of this class by calling + * {@linkplain TerminalFactory#terminals}. + * + * @see TerminalFactory + * @see CardTerminal + * + * @since 1.6 + * @author Andreas Sterbenz + * @author JSR 268 Expert Group + */ +public abstract class CardTerminals { + + /** + * Constructs a new CardTerminals object. + * + *

This constructor is called by subclasses only. Application should + * call {@linkplain TerminalFactory#terminals} + * to obtain a CardTerminals object. + */ + protected CardTerminals() { + // empty + } + + /** + * Returns an unmodifiable list of all available terminals. + * + * @return an unmodifiable list of all available terminals. + * + * @throws CardException if the card operation failed + */ + public List list() throws CardException { + return list(State.ALL); + } + + /** + * Returns an unmodifiable list of all terminals matching the specified + * state. + * + *

If state is {@link State#ALL State.ALL}, this method returns + * all CardTerminals encapsulated by this object. + * If state is {@link State#CARD_PRESENT State.CARD_PRESENT} or + * {@link State#CARD_ABSENT State.CARD_ABSENT}, it returns all + * CardTerminals where a card is currently present or absent, respectively. + * + *

If state is {@link State#CARD_INSERTION State.CARD_INSERTION} or + * {@link State#CARD_REMOVAL State.CARD_REMOVAL}, it returns all + * CardTerminals for which an insertion (or removal, respectively) + * was detected during the last call to {@linkplain #waitForChange}. + * If waitForChange() has not been called on this object, + * CARD_INSERTION is equivalent to CARD_PRESENT + * and CARD_REMOVAL is equivalent to CARD_ABSENT. + * For an example of the use of CARD_INSERTION, + * see {@link #waitForChange}. + * + * @param state the State + * @return an unmodifiable list of all terminals matching the specified + * attribute. + * + * @throws NullPointerException if attr is null + * @throws CardException if the card operation failed + */ + public abstract List list(State state) throws CardException; + + /** + * Returns the terminal with the specified name or null if no such + * terminal exists. + * + * @return the terminal with the specified name or null if no such + * terminal exists. + * + * @throws NullPointerException if name is null + */ + public CardTerminal getTerminal(String name) { + if (name == null) { + throw new NullPointerException(); + } + try { + for (CardTerminal terminal : list()) { + if (terminal.getName().equals(name)) { + return terminal; + } + } + return null; + } catch (CardException e) { + return null; + } + } + + /** + * Waits for card insertion or removal in any of the terminals of this + * object. + * + *

This call is equivalent to calling + * {@linkplain #waitForChange(long) waitForChange(0)}. + * + * @throws IllegalStateException if this CardTerminals + * object does not contain any terminals + * @throws CardException if the card operation failed + */ + public void waitForChange() throws CardException { + waitForChange(0); + } + + /** + * Waits for card insertion or removal in any of the terminals of this + * object or until the timeout expires. + * + *

This method examines each CardTerminal of this object. + * If a card was inserted into or removed from a CardTerminal since the + * previous call to waitForChange(), it returns + * immediately. + * Otherwise, or if this is the first call to waitForChange() + * on this object, it blocks until a card is inserted into or removed from + * a CardTerminal. + * + *

If timeout is greater than 0, the method returns after + * timeout milliseconds even if there is no change in state. + * In that case, this method returns false; otherwise it + * returns true. + * + *

This method is often used in a loop in combination with + * {@link #list(CardTerminals.State) list(State.CARD_INSERTION)}, + * for example: + *

+     *  TerminalFactory factory = ...;
+     *  CardTerminals terminals = factory.terminals();
+     *  while (true) {
+     *      for (CardTerminal terminal : terminals.list(CARD_INSERTION)) {
+     *          // examine Card in terminal, return if it matches
+     *      }
+     *      terminals.waitForChange();
+     *  }
+ * + * @param timeout if positive, block for up to timeout + * milliseconds; if zero, block indefinitely; must not be negative + * @return false if the method returns due to an expired timeout, + * true otherwise. + * + * @throws IllegalStateException if this CardTerminals + * object does not contain any terminals + * @throws IllegalArgumentException if timeout is negative + * @throws CardException if the card operation failed + */ + public abstract boolean waitForChange(long timeout) throws CardException; + + /** + * Enumeration of attributes of a CardTerminal. + * It is used as a parameter to the {@linkplain CardTerminals#list} method. + * + * @since 1.6 + */ + public static enum State { + /** + * All CardTerminals. + */ + ALL, + /** + * CardTerminals in which a card is present. + */ + CARD_PRESENT, + /** + * CardTerminals in which a card is not present. + */ + CARD_ABSENT, + /** + * CardTerminals for which a card insertion was detected during the + * latest call to {@linkplain State#waitForChange waitForChange()} + * call. + */ + CARD_INSERTION, + /** + * CardTerminals for which a card removal was detected during the + * latest call to {@linkplain State#waitForChange waitForChange()} + * call. + */ + CARD_REMOVAL, + } + +} diff --git a/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CommandAPDU.java b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CommandAPDU.java new file mode 100644 index 0000000..b1faa18 --- /dev/null +++ b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/CommandAPDU.java @@ -0,0 +1,606 @@ +/* + * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package javax.smartcardio; + +import java.util.Arrays; + +import java.nio.ByteBuffer; + +/** + * A command APDU following the structure defined in ISO/IEC 7816-4. + * It consists of a four byte header and a conditional body of variable length. + * This class does not attempt to verify that the APDU encodes a semantically + * valid command. + * + *

Note that when the expected length of the response APDU is specified + * in the {@linkplain #CommandAPDU(int,int,int,int,int) constructors}, + * the actual length (Ne) must be specified, not its + * encoded form (Le). Similarly, {@linkplain #getNe} returns the actual + * value Ne. In other words, a value of 0 means "no data in the response APDU" + * rather than "maximum length." + * + *

This class supports both the short and extended forms of length + * encoding for Ne and Nc. However, note that not all terminals and Smart Cards + * are capable of accepting APDUs that use the extended form. + * + *

For the header bytes CLA, INS, P1, and P2 the Java type int + * is used to represent the 8 bit unsigned values. In the constructors, only + * the 8 lowest bits of the int value specified by the application + * are significant. The accessor methods always return the byte as an unsigned + * value between 0 and 255. + * + *

Instances of this class are immutable. Where data is passed in or out + * via byte arrays, defensive cloning is performed. + * + * @see ResponseAPDU + * @see CardChannel#transmit CardChannel.transmit + * + * @since 1.6 + * @author Andreas Sterbenz + * @author JSR 268 Expert Group + */ +public final class CommandAPDU implements java.io.Serializable { + + private static final long serialVersionUID = 398698301286670877L; + + private static final int MAX_APDU_SIZE = 65544; + + /** @serial */ + private byte[] apdu; + + // value of nc + private transient int nc; + + // value of ne + private transient int ne; + + // index of start of data within the apdu array + private transient int dataOffset; + + /** + * Constructs a CommandAPDU from a byte array containing the complete + * APDU contents (header and body). + * + *

Note that the apdu bytes are copied to protect against + * subsequent modification. + * + * @param apdu the complete command APDU + * + * @throws NullPointerException if apdu is null + * @throws IllegalArgumentException if apdu does not contain a valid + * command APDU + */ + public CommandAPDU(byte[] apdu) { + this.apdu = apdu.clone(); + parse(); + } + + /** + * Constructs a CommandAPDU from a byte array containing the complete + * APDU contents (header and body). The APDU starts at the index + * apduOffset in the byte array and is apduLength + * bytes long. + * + *

Note that the apdu bytes are copied to protect against + * subsequent modification. + * + * @param apdu the complete command APDU + * @param apduOffset the offset in the byte array at which the apdu + * data begins + * @param apduLength the length of the APDU + * + * @throws NullPointerException if apdu is null + * @throws IllegalArgumentException if apduOffset or apduLength are + * negative or if apduOffset + apduLength are greater than apdu.length, + * or if the specified bytes are not a valid APDU + */ + public CommandAPDU(byte[] apdu, int apduOffset, int apduLength) { + checkArrayBounds(apdu, apduOffset, apduLength); + this.apdu = new byte[apduLength]; + System.arraycopy(apdu, apduOffset, this.apdu, 0, apduLength); + parse(); + } + + private void checkArrayBounds(byte[] b, int ofs, int len) { + if ((ofs < 0) || (len < 0)) { + throw new IllegalArgumentException + ("Offset and length must not be negative"); + } + if (b == null) { + if ((ofs != 0) && (len != 0)) { + throw new IllegalArgumentException + ("offset and length must be 0 if array is null"); + } + } else { + if (ofs > b.length - len) { + throw new IllegalArgumentException + ("Offset plus length exceed array size"); + } + } + } + + /** + * Creates a CommandAPDU from the ByteBuffer containing the complete APDU + * contents (header and body). + * The buffer's position must be set to the start of the APDU, + * its limit to the end of the APDU. Upon return, the buffer's + * position is equal to its limit; its limit remains unchanged. + * + *

Note that the data in the ByteBuffer is copied to protect against + * subsequent modification. + * + * @param apdu the ByteBuffer containing the complete APDU + * + * @throws NullPointerException if apdu is null + * @throws IllegalArgumentException if apdu does not contain a valid + * command APDU + */ + public CommandAPDU(ByteBuffer apdu) { + this.apdu = new byte[apdu.remaining()]; + apdu.get(this.apdu); + parse(); + } + + /** + * Constructs a CommandAPDU from the four header bytes. This is case 1 + * in ISO 7816, no command body. + * + * @param cla the class byte CLA + * @param ins the instruction byte INS + * @param p1 the parameter byte P1 + * @param p2 the parameter byte P2 + */ + public CommandAPDU(int cla, int ins, int p1, int p2) { + this(cla, ins, p1, p2, null, 0, 0, 0); + } + + /** + * Constructs a CommandAPDU from the four header bytes and the expected + * response data length. This is case 2 in ISO 7816, empty command data + * field with Ne specified. If Ne is 0, the APDU is encoded as ISO 7816 + * case 1. + * + * @param cla the class byte CLA + * @param ins the instruction byte INS + * @param p1 the parameter byte P1 + * @param p2 the parameter byte P2 + * @param ne the maximum number of expected data bytes in a response APDU + * + * @throws IllegalArgumentException if ne is negative or greater than + * 65536 + */ + public CommandAPDU(int cla, int ins, int p1, int p2, int ne) { + this(cla, ins, p1, p2, null, 0, 0, ne); + } + + /** + * Constructs a CommandAPDU from the four header bytes and command data. + * This is case 3 in ISO 7816, command data present and Ne absent. The + * value Nc is taken as data.length. If data is null or + * its length is 0, the APDU is encoded as ISO 7816 case 1. + * + *

Note that the data bytes are copied to protect against + * subsequent modification. + * + * @param cla the class byte CLA + * @param ins the instruction byte INS + * @param p1 the parameter byte P1 + * @param p2 the parameter byte P2 + * @param data the byte array containing the data bytes of the command body + * + * @throws IllegalArgumentException if data.length is greater than 65535 + */ + public CommandAPDU(int cla, int ins, int p1, int p2, byte[] data) { + this(cla, ins, p1, p2, data, 0, arrayLength(data), 0); + } + + /** + * Constructs a CommandAPDU from the four header bytes and command data. + * This is case 3 in ISO 7816, command data present and Ne absent. The + * value Nc is taken as dataLength. If dataLength + * is 0, the APDU is encoded as ISO 7816 case 1. + * + *

Note that the data bytes are copied to protect against + * subsequent modification. + * + * @param cla the class byte CLA + * @param ins the instruction byte INS + * @param p1 the parameter byte P1 + * @param p2 the parameter byte P2 + * @param data the byte array containing the data bytes of the command body + * @param dataOffset the offset in the byte array at which the data + * bytes of the command body begin + * @param dataLength the number of the data bytes in the command body + * + * @throws NullPointerException if data is null and dataLength is not 0 + * @throws IllegalArgumentException if dataOffset or dataLength are + * negative or if dataOffset + dataLength are greater than data.length + * or if dataLength is greater than 65535 + */ + public CommandAPDU(int cla, int ins, int p1, int p2, byte[] data, + int dataOffset, int dataLength) { + this(cla, ins, p1, p2, data, dataOffset, dataLength, 0); + } + + /** + * Constructs a CommandAPDU from the four header bytes, command data, + * and expected response data length. This is case 4 in ISO 7816, + * command data and Ne present. The value Nc is taken as data.length + * if data is non-null and as 0 otherwise. If Ne or Nc + * are zero, the APDU is encoded as case 1, 2, or 3 per ISO 7816. + * + *

Note that the data bytes are copied to protect against + * subsequent modification. + * + * @param cla the class byte CLA + * @param ins the instruction byte INS + * @param p1 the parameter byte P1 + * @param p2 the parameter byte P2 + * @param data the byte array containing the data bytes of the command body + * @param ne the maximum number of expected data bytes in a response APDU + * + * @throws IllegalArgumentException if data.length is greater than 65535 + * or if ne is negative or greater than 65536 + */ + public CommandAPDU(int cla, int ins, int p1, int p2, byte[] data, int ne) { + this(cla, ins, p1, p2, data, 0, arrayLength(data), ne); + } + + private static int arrayLength(byte[] b) { + return (b != null) ? b.length : 0; + } + + /** + * Command APDU encoding options: + * + * case 1: |CLA|INS|P1 |P2 | len = 4 + * case 2s: |CLA|INS|P1 |P2 |LE | len = 5 + * case 3s: |CLA|INS|P1 |P2 |LC |...BODY...| len = 6..260 + * case 4s: |CLA|INS|P1 |P2 |LC |...BODY...|LE | len = 7..261 + * case 2e: |CLA|INS|P1 |P2 |00 |LE1|LE2| len = 7 + * case 3e: |CLA|INS|P1 |P2 |00 |LC1|LC2|...BODY...| len = 8..65542 + * case 4e: |CLA|INS|P1 |P2 |00 |LC1|LC2|...BODY...|LE1|LE2| len =10..65544 + * + * LE, LE1, LE2 may be 0x00. + * LC must not be 0x00 and LC1|LC2 must not be 0x00|0x00 + */ + private void parse() { + if (apdu.length < 4) { + throw new IllegalArgumentException("apdu must be at least 4 bytes long"); + } + if (apdu.length == 4) { + // case 1 + return; + } + int l1 = apdu[4] & 0xff; + if (apdu.length == 5) { + // case 2s + this.ne = (l1 == 0) ? 256 : l1; + return; + } + if (l1 != 0) { + if (apdu.length == 4 + 1 + l1) { + // case 3s + this.nc = l1; + this.dataOffset = 5; + return; + } else if (apdu.length == 4 + 2 + l1) { + // case 4s + this.nc = l1; + this.dataOffset = 5; + int l2 = apdu[apdu.length - 1] & 0xff; + this.ne = (l2 == 0) ? 256 : l2; + return; + } else { + throw new IllegalArgumentException + ("Invalid APDU: length=" + apdu.length + ", b1=" + l1); + } + } + if (apdu.length < 7) { + throw new IllegalArgumentException + ("Invalid APDU: length=" + apdu.length + ", b1=" + l1); + } + int l2 = ((apdu[5] & 0xff) << 8) | (apdu[6] & 0xff); + if (apdu.length == 7) { + // case 2e + this.ne = (l2 == 0) ? 65536 : l2; + return; + } + if (l2 == 0) { + throw new IllegalArgumentException("Invalid APDU: length=" + + apdu.length + ", b1=" + l1 + ", b2||b3=" + l2); + } + if (apdu.length == 4 + 3 + l2) { + // case 3e + this.nc = l2; + this.dataOffset = 7; + return; + } else if (apdu.length == 4 + 5 + l2) { + // case 4e + this.nc = l2; + this.dataOffset = 7; + int leOfs = apdu.length - 2; + int l3 = ((apdu[leOfs] & 0xff) << 8) | (apdu[leOfs + 1] & 0xff); + this.ne = (l3 == 0) ? 65536 : l3; + } else { + throw new IllegalArgumentException("Invalid APDU: length=" + + apdu.length + ", b1=" + l1 + ", b2||b3=" + l2); + } + } + + /** + * Constructs a CommandAPDU from the four header bytes, command data, + * and expected response data length. This is case 4 in ISO 7816, + * command data and Le present. The value Nc is taken as + * dataLength. + * If Ne or Nc + * are zero, the APDU is encoded as case 1, 2, or 3 per ISO 7816. + * + *

Note that the data bytes are copied to protect against + * subsequent modification. + * + * @param cla the class byte CLA + * @param ins the instruction byte INS + * @param p1 the parameter byte P1 + * @param p2 the parameter byte P2 + * @param data the byte array containing the data bytes of the command body + * @param dataOffset the offset in the byte array at which the data + * bytes of the command body begin + * @param dataLength the number of the data bytes in the command body + * @param ne the maximum number of expected data bytes in a response APDU + * + * @throws NullPointerException if data is null and dataLength is not 0 + * @throws IllegalArgumentException if dataOffset or dataLength are + * negative or if dataOffset + dataLength are greater than data.length, + * or if ne is negative or greater than 65536, + * or if dataLength is greater than 65535 + */ + public CommandAPDU(int cla, int ins, int p1, int p2, byte[] data, + int dataOffset, int dataLength, int ne) { + checkArrayBounds(data, dataOffset, dataLength); + if (dataLength > 65535) { + throw new IllegalArgumentException("dataLength is too large"); + } + if (ne < 0) { + throw new IllegalArgumentException("ne must not be negative"); + } + if (ne > 65536) { + throw new IllegalArgumentException("ne is too large"); + } + this.ne = ne; + this.nc = dataLength; + if (dataLength == 0) { + if (ne == 0) { + // case 1 + this.apdu = new byte[4]; + setHeader(cla, ins, p1, p2); + } else { + // case 2s or 2e + if (ne <= 256) { + // case 2s + // 256 is encoded as 0x00 + byte len = (ne != 256) ? (byte)ne : 0; + this.apdu = new byte[5]; + setHeader(cla, ins, p1, p2); + this.apdu[4] = len; + } else { + // case 2e + byte l1, l2; + // 65536 is encoded as 0x00 0x00 + if (ne == 65536) { + l1 = 0; + l2 = 0; + } else { + l1 = (byte)(ne >> 8); + l2 = (byte)ne; + } + this.apdu = new byte[7]; + setHeader(cla, ins, p1, p2); + this.apdu[5] = l1; + this.apdu[6] = l2; + } + } + } else { + if (ne == 0) { + // case 3s or 3e + if (dataLength <= 255) { + // case 3s + apdu = new byte[4 + 1 + dataLength]; + setHeader(cla, ins, p1, p2); + apdu[4] = (byte)dataLength; + this.dataOffset = 5; + System.arraycopy(data, dataOffset, apdu, 5, dataLength); + } else { + // case 3e + apdu = new byte[4 + 3 + dataLength]; + setHeader(cla, ins, p1, p2); + apdu[4] = 0; + apdu[5] = (byte)(dataLength >> 8); + apdu[6] = (byte)dataLength; + this.dataOffset = 7; + System.arraycopy(data, dataOffset, apdu, 7, dataLength); + } + } else { + // case 4s or 4e + if ((dataLength <= 255) && (ne <= 256)) { + // case 4s + apdu = new byte[4 + 2 + dataLength]; + setHeader(cla, ins, p1, p2); + apdu[4] = (byte)dataLength; + this.dataOffset = 5; + System.arraycopy(data, dataOffset, apdu, 5, dataLength); + apdu[apdu.length - 1] = (ne != 256) ? (byte)ne : 0; + } else { + // case 4e + apdu = new byte[4 + 5 + dataLength]; + setHeader(cla, ins, p1, p2); + apdu[4] = 0; + apdu[5] = (byte)(dataLength >> 8); + apdu[6] = (byte)dataLength; + this.dataOffset = 7; + System.arraycopy(data, dataOffset, apdu, 7, dataLength); + if (ne != 65536) { + int leOfs = apdu.length - 2; + apdu[leOfs] = (byte)(ne >> 8); + apdu[leOfs + 1] = (byte)ne; + } // else le == 65536: no need to fill in, encoded as 0 + } + } + } + } + + private void setHeader(int cla, int ins, int p1, int p2) { + apdu[0] = (byte)cla; + apdu[1] = (byte)ins; + apdu[2] = (byte)p1; + apdu[3] = (byte)p2; + } + + /** + * Returns the value of the class byte CLA. + * + * @return the value of the class byte CLA. + */ + public int getCLA() { + return apdu[0] & 0xff; + } + + /** + * Returns the value of the instruction byte INS. + * + * @return the value of the instruction byte INS. + */ + public int getINS() { + return apdu[1] & 0xff; + } + + /** + * Returns the value of the parameter byte P1. + * + * @return the value of the parameter byte P1. + */ + public int getP1() { + return apdu[2] & 0xff; + } + + /** + * Returns the value of the parameter byte P2. + * + * @return the value of the parameter byte P2. + */ + public int getP2() { + return apdu[3] & 0xff; + } + + /** + * Returns the number of data bytes in the command body (Nc) or 0 if this + * APDU has no body. This call is equivalent to + * getData().length. + * + * @return the number of data bytes in the command body or 0 if this APDU + * has no body. + */ + public int getNc() { + return nc; + } + + /** + * Returns a copy of the data bytes in the command body. If this APDU as + * no body, this method returns a byte array with length zero. + * + * @return a copy of the data bytes in the command body or the empty + * byte array if this APDU has no body. + */ + public byte[] getData() { + byte[] data = new byte[nc]; + System.arraycopy(apdu, dataOffset, data, 0, nc); + return data; + } + + /** + * Returns the maximum number of expected data bytes in a response + * APDU (Ne). + * + * @return the maximum number of expected data bytes in a response APDU. + */ + public int getNe() { + return ne; + } + + /** + * Returns a copy of the bytes in this APDU. + * + * @return a copy of the bytes in this APDU. + */ + public byte[] getBytes() { + return apdu.clone(); + } + + /** + * Returns a string representation of this command APDU. + * + * @return a String representation of this command APDU. + */ + public String toString() { + return "CommmandAPDU: " + apdu.length + " bytes, nc=" + nc + ", ne=" + ne; + } + + /** + * Compares the specified object with this command APDU for equality. + * Returns true if the given object is also a CommandAPDU and its bytes are + * identical to the bytes in this CommandAPDU. + * + * @param obj the object to be compared for equality with this command APDU + * @return true if the specified object is equal to this command APDU + */ + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof CommandAPDU == false) { + return false; + } + CommandAPDU other = (CommandAPDU)obj; + return Arrays.equals(this.apdu, other.apdu); + } + + /** + * Returns the hash code value for this command APDU. + * + * @return the hash code value for this command APDU. + */ + public int hashCode() { + return Arrays.hashCode(apdu); + } + + private void readObject(java.io.ObjectInputStream in) + throws java.io.IOException, ClassNotFoundException { + apdu = (byte[])in.readUnshared(); + // initialize transient fields + parse(); + } + +} diff --git a/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/ResponseAPDU.java b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/ResponseAPDU.java new file mode 100644 index 0000000..4498cb0 --- /dev/null +++ b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/ResponseAPDU.java @@ -0,0 +1,185 @@ +/* + * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package javax.smartcardio; + +import java.util.Arrays; + +/** + * A response APDU as defined in ISO/IEC 7816-4. It consists of a conditional + * body and a two byte trailer. + * This class does not attempt to verify that the APDU encodes a semantically + * valid response. + * + *

Instances of this class are immutable. Where data is passed in or out + * via byte arrays, defensive cloning is performed. + * + * @see CommandAPDU + * @see CardChannel#transmit CardChannel.transmit + * + * @since 1.6 + * @author Andreas Sterbenz + * @author JSR 268 Expert Group + */ +public final class ResponseAPDU implements java.io.Serializable { + + private static final long serialVersionUID = 6962744978375594225L; + + /** @serial */ + private byte[] apdu; + + /** + * Constructs a ResponseAPDU from a byte array containing the complete + * APDU contents (conditional body and trailed). + * + *

Note that the byte array is cloned to protect against subsequent + * modification. + * + * @param apdu the complete response APDU + * + * @throws NullPointerException if apdu is null + * @throws IllegalArgumentException if apdu.length is less than 2 + */ + public ResponseAPDU(byte[] apdu) { + apdu = apdu.clone(); + check(apdu); + this.apdu = apdu; + } + + private static void check(byte[] apdu) { + if (apdu.length < 2) { + throw new IllegalArgumentException("apdu must be at least 2 bytes long"); + } + } + + /** + * Returns the number of data bytes in the response body (Nr) or 0 if this + * APDU has no body. This call is equivalent to + * getData().length. + * + * @return the number of data bytes in the response body or 0 if this APDU + * has no body. + */ + public int getNr() { + return apdu.length - 2; + } + + /** + * Returns a copy of the data bytes in the response body. If this APDU as + * no body, this method returns a byte array with a length of zero. + * + * @return a copy of the data bytes in the response body or the empty + * byte array if this APDU has no body. + */ + public byte[] getData() { + byte[] data = new byte[apdu.length - 2]; + System.arraycopy(apdu, 0, data, 0, data.length); + return data; + } + + /** + * Returns the value of the status byte SW1 as a value between 0 and 255. + * + * @return the value of the status byte SW1 as a value between 0 and 255. + */ + public int getSW1() { + return apdu[apdu.length - 2] & 0xff; + } + + /** + * Returns the value of the status byte SW2 as a value between 0 and 255. + * + * @return the value of the status byte SW2 as a value between 0 and 255. + */ + public int getSW2() { + return apdu[apdu.length - 1] & 0xff; + } + + /** + * Returns the value of the status bytes SW1 and SW2 as a single + * status word SW. + * It is defined as + * (getSW1() << 8) | getSW2(). + * + * @return the value of the status word SW. + */ + public int getSW() { + return (getSW1() << 8) | getSW2(); + } + + /** + * Returns a copy of the bytes in this APDU. + * + * @return a copy of the bytes in this APDU. + */ + public byte[] getBytes() { + return apdu.clone(); + } + + /** + * Returns a string representation of this response APDU. + * + * @return a String representation of this response APDU. + */ + public String toString() { + return "ResponseAPDU: " + apdu.length + " bytes, SW=" + + Integer.toHexString(getSW()); + } + + /** + * Compares the specified object with this response APDU for equality. + * Returns true if the given object is also a ResponseAPDU and its bytes are + * identical to the bytes in this ResponseAPDU. + * + * @param obj the object to be compared for equality with this response APDU + * @return true if the specified object is equal to this response APDU + */ + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof ResponseAPDU == false) { + return false; + } + ResponseAPDU other = (ResponseAPDU)obj; + return Arrays.equals(this.apdu, other.apdu); + } + + /** + * Returns the hash code value for this response APDU. + * + * @return the hash code value for this response APDU. + */ + public int hashCode() { + return Arrays.hashCode(apdu); + } + + private void readObject(java.io.ObjectInputStream in) + throws java.io.IOException, ClassNotFoundException { + apdu = (byte[])in.readUnshared(); + check(apdu); + } + +} diff --git a/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/TerminalFactorySpi.java b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/TerminalFactorySpi.java new file mode 100644 index 0000000..500113c --- /dev/null +++ b/ACardEmulator/app/src/main/external/android-scio/src/main/java/javax/smartcardio/TerminalFactorySpi.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javax.smartcardio; + +import java.util.*; + +/** + * The TerminalFactorySpi class defines the service provider interface. + * Applications do not access this class directly, instead see + * {@linkplain TerminalFactory}. + * + *

Service providers that want to write a new implementation should define + * a concrete subclass of TerminalFactorySpi with a constructor that takes + * an Object as parameter. That class needs to be registered + * in a {@linkplain java.security.Provider}. The engine + * {@linkplain java.security.Provider.Service#getType type} is + * TerminalFactory. + * Service providers also need to implement subclasses of the abstract classes + * {@linkplain CardTerminals}, {@linkplain CardTerminal}, {@linkplain Card}, + * and {@linkplain CardChannel}. + * + *

For example: + *

file MyProvider.java:
+ *
+ * package com.somedomain.card;
+ *
+ * import java.security.Provider;
+ *
+ * public class MyProvider extends Provider {
+ *     public MyProvider() {
+ *         super("MyProvider", 1.0d, "Smart Card Example");
+ *         put("TerminalFactory.MyType", "com.somedomain.card.MySpi");
+ *     }
+ * }
+ *
+ *file MySpi.java
+ *
+ * package com.somedomain.card;
+ *
+ * import javax.smartcardio.*;
+ *
+ * public class MySpi extends TerminalFactoySpi {
+ *      public MySpi(Object parameter) {
+ *          // initialize as appropriate
+ *      }
+ *      protected CardTerminals engineTerminals() {
+ *          // add implementation code here
+ *      }
+ * }
+ * 
+ * + * @see TerminalFactory + * @see java.security.Provider + * + * @since 1.6 + * @author Andreas Sterbenz + * @author JSR 268 Expert Group + */ +public abstract class TerminalFactorySpi { + + /** + * Constructs a new TerminalFactorySpi object. + * + *

This class is part of the service provider interface and not accessed + * directly by applications. Applications + * should use TerminalFactory objects, which can be obtained by calling + * one of the + * {@linkplain TerminalFactory#getInstance TerminalFactory.getInstance()} + * methods. + * + *

Concrete subclasses should define a constructor that takes an + * Object as parameter. It will be invoked when an + * application calls one of the {@linkplain TerminalFactory#getInstance + * TerminalFactory.getInstance()} methods and receives the params + * object specified by the application. + */ + protected TerminalFactorySpi() { + // empty + } + + /** + * Returns the CardTerminals created by this factory. + * + * @return the CardTerminals created by this factory. + */ + protected abstract CardTerminals engineTerminals(); + +} diff --git a/ACardEmulator/app/src/main/external/jcardsim b/ACardEmulator/app/src/main/external/jcardsim new file mode 160000 index 0000000..8543076 --- /dev/null +++ b/ACardEmulator/app/src/main/external/jcardsim @@ -0,0 +1 @@ +Subproject commit 8543076c555fabdfd4ae5140d6413f9e62446bf2 diff --git a/ACardEmulator/app/src/main/external/ykneo-oath b/ACardEmulator/app/src/main/external/ykneo-oath new file mode 160000 index 0000000..341cd0a --- /dev/null +++ b/ACardEmulator/app/src/main/external/ykneo-oath @@ -0,0 +1 @@ +Subproject commit 341cd0a8d9f1d8f8020d60499122d098ed3677de diff --git a/ACardEmulator/app/src/main/external/ykneo-openpgp b/ACardEmulator/app/src/main/external/ykneo-openpgp new file mode 160000 index 0000000..9ae01d9 --- /dev/null +++ b/ACardEmulator/app/src/main/external/ykneo-openpgp @@ -0,0 +1 @@ +Subproject commit 9ae01d961ab9b5aa8c4f68bc58db176912090a34 diff --git a/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/MainActivity.java b/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/MainActivity.java new file mode 100644 index 0000000..fd01d42 --- /dev/null +++ b/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/MainActivity.java @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2015 Frank Morgner + * + * This file is part of ACardEmulator. + * + * ACardEmulator is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * ACardEmulator is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * ACardEmulator. If not, see . + */ + +package com.vsmartcard.acardemulator; + +import android.content.BroadcastReceiver; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.support.v4.content.LocalBroadcastManager; +import android.support.v7.app.ActionBarActivity; +import android.os.Bundle; +import android.text.Layout; +import android.text.method.ScrollingMovementMethod; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.TextView; +import android.widget.Toast; + + +public class MainActivity extends ActionBarActivity { + + private TextView textViewVPCDStatus; + private BroadcastReceiver bReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getAction().equals(SimulatorService.TAG)) { + String capdu = intent.getStringExtra(SimulatorService.EXTRA_CAPDU); + String rapdu = intent.getStringExtra(SimulatorService.EXTRA_RAPDU); + String error = intent.getStringExtra(SimulatorService.EXTRA_ERROR); + String deselect = intent.getStringExtra(SimulatorService.EXTRA_DESELECT); + String install = intent.getStringExtra(SimulatorService.EXTRA_INSTALL); + if (install != null) + textViewVPCDStatus.append(getResources().getString(R.string.status_install) + ":" + install + "\n"); + if (capdu != null) + textViewVPCDStatus.append(getResources().getString(R.string.status_capdu) + ": " + capdu + "\n"); + if (error != null) + textViewVPCDStatus.append(getResources().getString(R.string.status_error) + ": " + error + "\n"); + if (rapdu != null) { + textViewVPCDStatus.append(getResources().getString(R.string.status_rapdu) + ": " + rapdu + "\n"); + Layout layout = textViewVPCDStatus.getLayout(); + if (layout != null) { + int scrollAmount = layout.getLineTop(textViewVPCDStatus.getLineCount()) - textViewVPCDStatus.getHeight(); + if (scrollAmount > 0) + textViewVPCDStatus.scrollTo(0, scrollAmount); + else + textViewVPCDStatus.scrollTo(0, 0); + } + } + if (deselect != null) + textViewVPCDStatus.append(getResources().getString(R.string.status_disconnected) + ": " + deselect + "\n"); + } + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + textViewVPCDStatus = (TextView) findViewById(R.id.textViewLog); + textViewVPCDStatus.setMovementMethod(new ScrollingMovementMethod()); + + LocalBroadcastManager bManager = LocalBroadcastManager.getInstance(this); + IntentFilter intentFilter = new IntentFilter(); + intentFilter.addAction(SimulatorService.TAG); + bManager.registerReceiver(bReceiver, intentFilter); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.main, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle presses on the action bar items + switch (item.getItemId()) { + case R.id.action_copy: + // Code to Copy the content of Text View to the Clip board. + ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("simple text", textViewVPCDStatus.getText()); + clipboard.setPrimaryClip(clip); + Toast.makeText(getApplicationContext(), "Log copied to clipboard.", + Toast.LENGTH_LONG).show(); + return true; + case R.id.action_delete: + textViewVPCDStatus.setText(""); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + + + private static String saved_status_key = "textViewVPCDStatus"; + @Override + public void onRestoreInstanceState(Bundle savedInstanceState) { + super.onRestoreInstanceState(savedInstanceState); + textViewVPCDStatus.setText(savedInstanceState.getCharSequence(saved_status_key)); + } + @Override + public void onSaveInstanceState(Bundle savedInstanceState) { + savedInstanceState.putCharSequence(saved_status_key, textViewVPCDStatus.getText()); + super.onSaveInstanceState(savedInstanceState); + } +} diff --git a/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/Settings.java b/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/Settings.java new file mode 100644 index 0000000..759d127 --- /dev/null +++ b/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/Settings.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2014 Frank Morgner + * + * This file is part of RemoteSmartCardReader. + * + * RemoteSmartCardReader is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * RemoteSmartCardReader is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * RemoteSmartCardReader. If not, see . + */ + +package com.vsmartcard.acardemulator; + +import android.app.Activity; +import android.content.Context; +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; +import android.preference.PreferenceManager; + +import com.licel.jcardsim.base.Simulator; + +import net.pwendland.javacard.pki.isoapplet.FileNotFoundException; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +public class Settings { + + private final Context context; + private static final String simulatorFilename = "simulator"; + + public Settings (Context activity) { + context = activity; + } + + public void witeObjectToFile(String filename, Object object) { + + ObjectOutputStream objectOut = null; + try { + FileOutputStream fileOut = context.openFileOutput(filename, Activity.MODE_PRIVATE); + objectOut = new ObjectOutputStream(fileOut); + objectOut.writeObject(object); + fileOut.getFD().sync(); + + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (objectOut != null) { + try { + objectOut.close(); + } catch (IOException e) { + // do nowt + } + } + } + } + + public Object readObjectFromFile(String filename) { + ObjectInputStream objectIn = null; + Object object = null; + try { + + FileInputStream fileIn = context.getApplicationContext().openFileInput(filename); + objectIn = new ObjectInputStream(fileIn); + object = objectIn.readObject(); + + } catch (java.io.FileNotFoundException e) { + // Do nothing + } catch (IOException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } finally { + if (objectIn != null) { + try { + objectIn.close(); + } catch (IOException e) { + // do nowt + } + } + } + + return object; + } + + public void setSimulator(Simulator simulator) { + witeObjectToFile(simulatorFilename, simulator); + } + + public Simulator getSimulator() { + Object object = readObjectFromFile(simulatorFilename); + if (object == null) { + // TODO + return new Simulator(); + } else { + return (Simulator) object; + } + } +} \ No newline at end of file diff --git a/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/SimulatorService.java b/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/SimulatorService.java new file mode 100644 index 0000000..1ad58e9 --- /dev/null +++ b/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/SimulatorService.java @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2015 Frank Morgner + * + * This file is part of ACardEmulator. + * + * ACardEmulator is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * ACardEmulator is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * ACardEmulator. If not, see . + */ + +package com.vsmartcard.acardemulator; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.nfc.cardemulation.HostApduService; +import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; + +import com.licel.jcardsim.samples.HelloWorldApplet; +import com.licel.jcardsim.smartcardio.CardSimulator; +import com.licel.jcardsim.utils.AIDUtil; + +import net.pwendland.javacard.pki.isoapplet.IsoApplet; + +import openpgpcard.OpenPGPApplet; +import pkgYkneoOath.YkneoOath; + +public class SimulatorService extends HostApduService { + + public static final String TAG = "com.vsmartcard.acardemulator.SimulatorService"; + public static final String EXTRA_CAPDU = "MSG_CAPDU"; + public static final String EXTRA_RAPDU = "MSG_RAPDU"; + public static final String EXTRA_ERROR = "MSG_ERROR"; + public static final String EXTRA_DESELECT = "MSG_DESELECT"; + public static final String EXTRA_INSTALL = "MSG_INSTALL"; + + private static CardSimulator simulator = null; + + private void createSimulator() { + String aid, name, extra_install = "", extra_error = ""; + simulator = new CardSimulator(); + + name = getResources().getString(R.string.applet_helloworld); + aid = getResources().getString(R.string.aid_helloworld); + try { + simulator.installApplet(AIDUtil.create(aid), HelloWorldApplet.class); + extra_install += "\n" + name + " (AID: " + aid + ")"; + } catch (Exception e) { + e.printStackTrace(); + extra_error += "\n" + "Could not install " + name + " (AID: " + aid + ")"; + } + + name = getResources().getString(R.string.applet_isoapplet); + aid = getResources().getString(R.string.aid_isoapplet); + try { + simulator.installApplet(AIDUtil.create(aid), IsoApplet.class); + extra_install += "\n" + name + " (AID: " + aid + ")"; + } catch (Exception e) { + e.printStackTrace(); + extra_error += "\n" + "Could not install " + name + " (AID: " + aid + ")"; + } + + name = getResources().getString(R.string.applet_openpgp); + aid = getResources().getString(R.string.aid_openpgp); + try { + byte[] aid_bytes = Util.hexStringToByteArray(aid); + byte[] inst_params = new byte[aid.length()+1]; + inst_params[0] = (byte) aid_bytes.length; + System.arraycopy(aid_bytes, 0, inst_params, 1, aid_bytes.length); + simulator.installApplet(AIDUtil.create(aid), OpenPGPApplet.class, inst_params, (short) 0, (byte) inst_params.length); + extra_install += "\n" + name + " (AID: " + aid + ")"; + } catch (Exception e) { + e.printStackTrace(); + extra_error += "\n" + "Could not install " + name + " (AID: " + aid + ")"; + } + + name = getResources().getString(R.string.applet_oath); + aid = getResources().getString(R.string.aid_oath); + try { + byte[] aid_bytes = Util.hexStringToByteArray(aid); + byte[] inst_params = new byte[aid.length()+1]; + inst_params[0] = (byte) aid_bytes.length; + System.arraycopy(aid_bytes, 0, inst_params, 1, aid_bytes.length); + simulator.installApplet(AIDUtil.create(aid), YkneoOath.class, inst_params, (short) 0, (byte) inst_params.length); + extra_install += "\n" + name + " (AID: " + aid + ")"; + } catch (Exception e) { + e.printStackTrace(); + extra_error += "\n" + "Could not install " + name + " (AID: " + aid + ")"; + } + + Intent i = new Intent(TAG); + if (!extra_error.isEmpty()) + i.putExtra(EXTRA_ERROR, extra_error); + if (!extra_install.isEmpty()) + i.putExtra(EXTRA_INSTALL, extra_install); + LocalBroadcastManager.getInstance(this).sendBroadcast(i); + } + + @Override + public void onCreate () { + super.onCreate(); + + if (simulator == null) + createSimulator(); + } + + @Override + public byte[] processCommandApdu(byte[] capdu, Bundle extras) { + Intent i = new Intent(TAG); + String extra_error = ""; + byte[] rapdu = null; + + i.putExtra(EXTRA_CAPDU, Util.byteArrayToHexString(capdu)); + try { + rapdu = simulator.transmitCommand(capdu); + i.putExtra(EXTRA_RAPDU, Util.byteArrayToHexString(rapdu)); + } catch (Exception e) { + e.printStackTrace(); + extra_error += "Internal error"; + } + + if (!extra_error.isEmpty()) + i.putExtra(EXTRA_ERROR, extra_error); + + LocalBroadcastManager.getInstance(this).sendBroadcast(i); + + return rapdu; + } + + @Override + public void onDeactivated(int reason) { + Intent i = new Intent(TAG); + + switch (reason) { + case DEACTIVATION_LINK_LOSS: + i.putExtra(EXTRA_DESELECT, "link lost"); + break; + case DEACTIVATION_DESELECTED: + i.putExtra(EXTRA_DESELECT, "deactivated"); + break; + } + + LocalBroadcastManager.getInstance(this).sendBroadcast(i); + } + +} diff --git a/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/Util.java b/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/Util.java new file mode 100644 index 0000000..0fda72c --- /dev/null +++ b/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/Util.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2015 Frank Morgner + * + * This file is part of ACardEmulator. + * + * ACardEmulator is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * ACardEmulator is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * ACardEmulator. If not, see . + */ + +package com.vsmartcard.acardemulator; + +public class Util { + + public static byte[] hexStringToByteArray(String s) { + int len = s.length(); + byte[] data = new byte[len/2]; + + for(int i = 0; i < len; i+=2){ + data[i/2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i+1), 16)); + } + + return data; + } + + final protected static char[] hexArray = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; + public static String byteArrayToHexString(byte[] bytes) { + char[] hexChars = new char[bytes.length*2]; + int v; + + for(int j=0; j < bytes.length; j++) { + v = bytes[j] & 0xFF; + hexChars[j*2] = hexArray[v>>>4]; + hexChars[j*2 + 1] = hexArray[v & 0x0F]; + } + + return new String(hexChars); + } +} diff --git a/ACardEmulator/app/src/main/res/drawable-hdpi/ic_action_copy.png b/ACardEmulator/app/src/main/res/drawable-hdpi/ic_action_copy.png new file mode 100644 index 0000000..f97df1d Binary files /dev/null and b/ACardEmulator/app/src/main/res/drawable-hdpi/ic_action_copy.png differ diff --git a/ACardEmulator/app/src/main/res/drawable-hdpi/ic_action_delete.png b/ACardEmulator/app/src/main/res/drawable-hdpi/ic_action_delete.png new file mode 100755 index 0000000..572df98 Binary files /dev/null and b/ACardEmulator/app/src/main/res/drawable-hdpi/ic_action_delete.png differ diff --git a/ACardEmulator/app/src/main/res/drawable-hdpi/ic_launcher.png b/ACardEmulator/app/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..c1b44cc Binary files /dev/null and b/ACardEmulator/app/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/ACardEmulator/app/src/main/res/drawable-mdpi/ic_action_copy.png b/ACardEmulator/app/src/main/res/drawable-mdpi/ic_action_copy.png new file mode 100644 index 0000000..d846e72 Binary files /dev/null and b/ACardEmulator/app/src/main/res/drawable-mdpi/ic_action_copy.png differ diff --git a/ACardEmulator/app/src/main/res/drawable-mdpi/ic_action_delete.png b/ACardEmulator/app/src/main/res/drawable-mdpi/ic_action_delete.png new file mode 100755 index 0000000..c1a5e07 Binary files /dev/null and b/ACardEmulator/app/src/main/res/drawable-mdpi/ic_action_delete.png differ diff --git a/ACardEmulator/app/src/main/res/drawable-mdpi/ic_launcher.png b/ACardEmulator/app/src/main/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..a1bf709 Binary files /dev/null and b/ACardEmulator/app/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/ACardEmulator/app/src/main/res/drawable-xhdpi/ic_action_copy.png b/ACardEmulator/app/src/main/res/drawable-xhdpi/ic_action_copy.png new file mode 100644 index 0000000..a6e1aa2 Binary files /dev/null and b/ACardEmulator/app/src/main/res/drawable-xhdpi/ic_action_copy.png differ diff --git a/ACardEmulator/app/src/main/res/drawable-xhdpi/ic_action_delete.png b/ACardEmulator/app/src/main/res/drawable-xhdpi/ic_action_delete.png new file mode 100755 index 0000000..ead3322 Binary files /dev/null and b/ACardEmulator/app/src/main/res/drawable-xhdpi/ic_action_delete.png differ diff --git a/ACardEmulator/app/src/main/res/drawable-xhdpi/ic_launcher.png b/ACardEmulator/app/src/main/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..3b5ae5b Binary files /dev/null and b/ACardEmulator/app/src/main/res/drawable-xhdpi/ic_launcher.png differ diff --git a/ACardEmulator/app/src/main/res/drawable-xxhdpi/ic_action_copy.png b/ACardEmulator/app/src/main/res/drawable-xxhdpi/ic_action_copy.png new file mode 100644 index 0000000..a381cdc Binary files /dev/null and b/ACardEmulator/app/src/main/res/drawable-xxhdpi/ic_action_copy.png differ diff --git a/ACardEmulator/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/ACardEmulator/app/src/main/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..b7df51b Binary files /dev/null and b/ACardEmulator/app/src/main/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/ACardEmulator/app/src/main/res/layout/activity_main.xml b/ACardEmulator/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..b3c54ca --- /dev/null +++ b/ACardEmulator/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,29 @@ + + + + + + + \ No newline at end of file diff --git a/ACardEmulator/app/src/main/res/menu/main.xml b/ACardEmulator/app/src/main/res/menu/main.xml new file mode 100644 index 0000000..d9f2937 --- /dev/null +++ b/ACardEmulator/app/src/main/res/menu/main.xml @@ -0,0 +1,16 @@ +

+ + + + + + diff --git a/ACardEmulator/app/src/main/res/values/dimens.xml b/ACardEmulator/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..a0171a7 --- /dev/null +++ b/ACardEmulator/app/src/main/res/values/dimens.xml @@ -0,0 +1,6 @@ + + + 16dp + 16dp + + diff --git a/ACardEmulator/app/src/main/res/values/strings.xml b/ACardEmulator/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..f4807ba --- /dev/null +++ b/ACardEmulator/app/src/main/res/values/strings.xml @@ -0,0 +1,25 @@ + + + + Smart Card Emulator + + Error + Disconnected from terminal + C-APDU + R-APDU + Installed Applets + + Restart Emulator + Copy Log + Clear Log + + f276a288bcfba69d34f31001 + Philip Wendland\'s ISO Applet + F000000001 + jCardSim Team\'s Hello World Applet + D2760001240102000000000000010000 + Yubico\'s OpenPGP Applet + a000000527210101 + Yubico\'s OATH Applet + + diff --git a/ACardEmulator/app/src/main/res/values/styles.xml b/ACardEmulator/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..766ab99 --- /dev/null +++ b/ACardEmulator/app/src/main/res/values/styles.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/ACardEmulator/app/src/main/res/xml/aid_list.xml b/ACardEmulator/app/src/main/res/xml/aid_list.xml new file mode 100644 index 0000000..1540ca0 --- /dev/null +++ b/ACardEmulator/app/src/main/res/xml/aid_list.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/ACardEmulator/build.gradle b/ACardEmulator/build.gradle new file mode 100644 index 0000000..d3ff69d --- /dev/null +++ b/ACardEmulator/build.gradle @@ -0,0 +1,19 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.1.0' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + jcenter() + } +} diff --git a/ACardEmulator/gradle.properties b/ACardEmulator/gradle.properties new file mode 100644 index 0000000..1d3591c --- /dev/null +++ b/ACardEmulator/gradle.properties @@ -0,0 +1,18 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx10248m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true \ No newline at end of file diff --git a/ACardEmulator/gradle/wrapper/gradle-wrapper.jar b/ACardEmulator/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..8c0fb64 Binary files /dev/null and b/ACardEmulator/gradle/wrapper/gradle-wrapper.jar differ diff --git a/ACardEmulator/gradle/wrapper/gradle-wrapper.properties b/ACardEmulator/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..0c71e76 --- /dev/null +++ b/ACardEmulator/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Apr 10 15:27:10 PDT 2013 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip diff --git a/ACardEmulator/gradlew b/ACardEmulator/gradlew new file mode 100755 index 0000000..91a7e26 --- /dev/null +++ b/ACardEmulator/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/ACardEmulator/gradlew.bat b/ACardEmulator/gradlew.bat new file mode 100644 index 0000000..aec9973 --- /dev/null +++ b/ACardEmulator/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/ACardEmulator/settings.gradle b/ACardEmulator/settings.gradle new file mode 100644 index 0000000..e7b4def --- /dev/null +++ b/ACardEmulator/settings.gradle @@ -0,0 +1 @@ +include ':app'